Commit f730910d authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

New naming convention for fixers

parent d92b99eb
import lib2to3.fixer_base
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)
...@@ -6,7 +6,8 @@ from lib2to3.pytree import Leaf, Node ...@@ -6,7 +6,8 @@ from lib2to3.pytree import Leaf, Node
import os import os
import re import re
from my2to3.util import add_future, BaseFix from my2to3.util import add_future
from my2to3.fixes import BaseFix
trace_file_match = re.compile(r"^(.*)\|(.*)\|(.*) <type '(.*)'> / <type '(.*)'>$").match trace_file_match = re.compile(r"^(.*)\|(.*)\|(.*) <type '(.*)'> / <type '(.*)'>$").match
...@@ -46,7 +47,7 @@ def analyze_data(data): ...@@ -46,7 +47,7 @@ def analyze_data(data):
return False return False
class FixDivision(BaseFix): class FixDivisionSupport(BaseFix):
"""Rewrites division_traced(n, a, b) into Py2/Py3-compatible division """Rewrites division_traced(n, a, b) into Py2/Py3-compatible division
The `TRACE_FILE` environment variable must point to the trace data file. See The `TRACE_FILE` environment variable must point to the trace data file. See
...@@ -62,7 +63,7 @@ class FixDivision(BaseFix): ...@@ -62,7 +63,7 @@ class FixDivision(BaseFix):
""" """
def start_tree(self, tree, filename): def start_tree(self, tree, filename):
super(FixDivision, self).start_tree(tree, filename) super(FixDivisionSupport, self).start_tree(tree, filename)
self.absolute_filename = os.path.abspath(filename) self.absolute_filename = os.path.abspath(filename)
......
...@@ -6,10 +6,10 @@ from lib2to3.pygram import python_symbols as syms ...@@ -6,10 +6,10 @@ from lib2to3.pygram import python_symbols as syms
from lib2to3.pytree import Node from lib2to3.pytree import Node
import sys import sys
from my2to3.util import BaseFix from my2to3.fixes import BaseFix
class FixTraceDivision(BaseFix): class FixDivisionTrace(BaseFix):
"""Rewrites a/b into division_traced(a, b) """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: division_traced can be a function that looks up the stack and record the operand types, for example:
...@@ -30,7 +30,7 @@ class FixTraceDivision(BaseFix): ...@@ -30,7 +30,7 @@ class FixTraceDivision(BaseFix):
__builtin__.division_traced = division_traced __builtin__.division_traced = division_traced
""" """
def start_tree(self, tree, filename): def start_tree(self, tree, filename):
super(FixTraceDivision, self).start_tree(tree, filename) super(FixDivisionTrace, self).start_tree(tree, filename)
self.ids = defaultdict(int) self.ids = defaultdict(int)
def match(self, node): def match(self, node):
......
...@@ -9,7 +9,7 @@ class FixerTestCase(lib2to3FixerTestCase): ...@@ -9,7 +9,7 @@ class FixerTestCase(lib2to3FixerTestCase):
class testFixTraceDivision(FixerTestCase): class testFixTraceDivision(FixerTestCase):
fixer = "trace_division" fixer = "division_trace"
def test_simple_division(self): def test_simple_division(self):
b = """x / y""" b = """x / y"""
......
from lib2to3 import fixer_util from lib2to3 import fixer_util
import lib2to3.fixer_base
from lib2to3.pytree import Leaf, Node from lib2to3.pytree import Leaf, Node
from lib2to3.pgen2 import token from lib2to3.pgen2 import token
from lib2to3.pygram import python_symbols as syms 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 # https://github.com/python-modernize/python-modernize/blob/84d973cb7b8153f9f7f22c3574a59312b2372ccb/libmodernize/__init__.py#L10-49
...@@ -58,7 +47,6 @@ def check_future_import(node): ...@@ -58,7 +47,6 @@ def check_future_import(node):
assert 0, "strange import" assert 0, "strange import"
# https://github.com/python-modernize/python-modernize/blob/84d973cb7b8153f9f7f22c3574a59312b2372ccb/libmodernize/__init__.py#L51-L66 # https://github.com/python-modernize/python-modernize/blob/84d973cb7b8153f9f7f22c3574a59312b2372ccb/libmodernize/__init__.py#L51-L66
def add_future(node, symbol): def add_future(node, symbol):
......
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