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

Track the modified code in a more fine-grained fashion

parent 9ef4a74b
......@@ -12,6 +12,8 @@ from my2to3.util import parse_type
trace = create_table("division", "filename", "lineno", "id", "dividend_type", "divisor_type")
trace_modified = create_table("division_modified", "filename", "lineno", "id")
@register_tracing_function
def division_traced(id, dividend, divisor):
......@@ -72,10 +74,13 @@ class FixDivisionTrace(BaseFix):
comma = lib2to3.fixer_util.Comma()
comma.prefix = children[1].prefix
id_ = self.ids[lineno]
trace_modified(self.filename, lineno, id_)
new_node = lib2to3.fixer_util.Call(
lib2to3.fixer_util.Name("division_traced"),
args=(
lib2to3.fixer_util.Number(self.ids[lineno]),
lib2to3.fixer_util.Number(id_),
lib2to3.fixer_util.Comma(),
dividend,
comma,
......
......@@ -43,23 +43,17 @@ def get_fixers():
f for f in get_fixers_from_package("my2to3.fixes") if f.endswith("_trace")
]
trace_modified = create_table("modified", "fixer", "filename")
def apply_fixers(string, name):
# This function is inspired by refactoring_tool.refactor_file
encoding = tokenize.detect_encoding(lambda: string)[0]
string = string.decode(encoding) + u"\n" # '\n' to silence certain parse errors
for fixer in get_fixers():
refactoring_tool = RefactoringTool(fixer_names=[fixer])
tree = refactoring_tool.refactor_string(string, name)
if tree.was_changed:
trace_modified(fixer[17:-6], name)
string = unicode(tree)
refactoring_tool = RefactoringTool(fixer_names=get_fixers())
s = string + "\n" # Silence certain parse errors
encoding = tokenize.detect_encoding(lambda: s)[0]
s = s.decode(encoding)
s = unicode(refactoring_tool.refactor_string(s, name))
# The [:-1] is to take off the \n we added earlier
return string[:-1].encode(encoding)
return s[:-1].encode(encoding)
init_py = '__init__' + os.extsep + 'py'
......
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