Commit 61cdede9 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

New BaseFix class

parent 742b6566
import __builtin__
from collections import defaultdict
import lib2to3.fixer_base
import lib2to3.pgen2
from lib2to3.pygram import python_symbols as syms
from lib2to3.pytree import Leaf, Node
import os
import re
from my2to3.util import add_future
from my2to3.util import add_future, BaseFix
trace_file_match = re.compile(r"^(.*)\|(.*)\|(.*) <type '(.*)'> / <type '(.*)'>$").match
......@@ -47,7 +46,7 @@ def analyze_data(data):
return False
class FixDivision(lib2to3.fixer_base.BaseFix):
class FixDivision(BaseFix):
"""Rewrites division_traced(n, a, b) into Py2/Py3-compatible division
The `TRACE_FILE` environment variable must point to the trace data file. See
......
# https://lab.nexedi.com/nexedi/erp5/snippets/475
from collections import defaultdict
import lib2to3.fixer_base
import lib2to3.fixer_util
import lib2to3.pgen2
from lib2to3.pygram import python_symbols as syms
from lib2to3.pytree import Node
import sys
from my2to3.util import BaseFix
class FixTraceDivision(lib2to3.fixer_base.BaseFix):
class FixTraceDivision(BaseFix):
"""Rewrites a/b into division_traced(a, b)
division_traced can be a function that looks up the stack and record the operand types, for example:
......
from lib2to3 import fixer_util
import lib2to3.fixer_base
from lib2to3.pytree import Leaf, Node
from lib2to3.pgen2 import token
from lib2to3.pygram import python_symbols as syms
import os
class BaseFix(lib2to3.fixer_base.BaseFix):
def start_tree(self, tree, filename):
sep = '-' * 5 # Arbitrary
if sep in filename:
filename = filename.split(sep, 1)[1].replace(sep, os.sep)
super(BaseFix, self).start_tree(tree, filename)
# https://github.com/python-modernize/python-modernize/blob/84d973cb7b8153f9f7f22c3574a59312b2372ccb/libmodernize/__init__.py#L10-49
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment