Commit 39a46687 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

fix_division: always replace with '//' (for now)

parent a73f5fea
import builtins
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
......@@ -30,6 +33,14 @@ def parse_trace_data(filepath):
return traces
def analyze_data(data):
"""Indicates whether the division described by `data` should be modified into
`//`, or should remain as `/`
"""
# TODO:
return True
class FixDivision(lib2to3.fixer_base.BaseFix):
"""Rewrites division_traced(n, a, b) into Py2/Py3-compatible division
......@@ -55,5 +66,21 @@ class FixDivision(lib2to3.fixer_base.BaseFix):
id_ = int(node.children[1].children[1].children[0].value)
data = self.traces[self.absolute_filename][lineno][id_]
if not data:
return
# TODO: analyse `data`, and replace the node to rewrite code
if analyze_data(data):
operator = Leaf(lib2to3.pgen2.token.DOUBLESLASH, "//")
else:
operator = Leaf(lib2to3.pgen2.token.SLASH, "/")
operator.prefix = node.children[1].children[1].children[3].prefix
node.replace(
Node(
syms.term,
[
node.children[1].children[1].children[2].clone(),
operator,
node.children[1].children[1].children[4].clone()
],
prefix=node.prefix))
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