Commit 3817aa59 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

division_support: record the status of each modification

parent c671076a
...@@ -8,15 +8,23 @@ from my2to3.trace import get_data ...@@ -8,15 +8,23 @@ from my2to3.trace import get_data
from my2to3.util import add_future, data2types from my2to3.util import add_future, data2types
def analyze_types(types): # id is used to differentiate the divisions of the same line.
"""Indicates whether the division described by `data` should be modified into insert_support = create_table("division_support", "filename", "lineno", "id", "status")
`//`, or should remain as `/`
"""
if len(types) == 1: def analyze_data(data):
dividend, divisor = types[0] try:
if dividend is divisor is int: types = data2types(data)
return True except Exception as e:
return False # Probably, one type is not a builtins
return False, "unknown"
else:
if len(types) == 1:
dividend, divisor = types[0]
if dividend is divisor is int:
return True, "automatic"
return False, "manual"
class FixDivisionSupport(BaseFix): class FixDivisionSupport(BaseFix):
...@@ -35,7 +43,9 @@ class FixDivisionSupport(BaseFix): ...@@ -35,7 +43,9 @@ class FixDivisionSupport(BaseFix):
if not data: if not data:
return return
if analyze_types(data2types(data)): should_change, status = analyze_data(data)
insert_support(filename, lineno, id_, status)
if should_change:
add_future(node, 'division') add_future(node, 'division')
operator = Leaf(lib2to3.pgen2.token.DOUBLESLASH, "//") operator = Leaf(lib2to3.pgen2.token.DOUBLESLASH, "//")
else: else:
......
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