Skip to content

Commit 3b69bc1

Browse files
authored
Merge pull request #197 from azdkj532/fix-slash-equal
Fix slash equal in fix_classic_division
2 parents de255c6 + 32be859 commit 3b69bc1

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

libmodernize/fixes/fix_classic_division.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@
88

99

1010
class FixClassicDivision(fixer_base.BaseFix):
11-
_accept_type = token.SLASH
11+
PATTERN = '''
12+
'/=' | '/'
13+
'''
1214

1315
def start_tree(self, tree, name):
1416
super(FixClassicDivision, self).start_tree(tree, name)
1517
self.skip = "division" in tree.future_features
1618

1719
def match(self, node):
18-
return node.value == "/"
20+
return node.value in ('/', '/=')
1921

2022
def transform(self, node, results):
2123
if self.skip:
2224
return
2325
libmodernize.add_future(node, u'division')
24-
return pytree.Leaf(token.SLASH, "//", prefix=node.prefix)
26+
27+
if node.value == '/':
28+
return pytree.Leaf(token.DOUBLESLASH, '//', prefix=node.prefix)
29+
else:
30+
return pytree.Leaf(token.DOUBLESLASHEQUAL, '//=', prefix=node.prefix)

tests/test_fix_classic_division.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@
44

55

66
CLASSIC_DIVISION = ("""\
7+
a /= 3
78
1 / 2
89
""",
910
"""\
1011
from __future__ import division
12+
a //= 3
1113
1 // 2
1214
""")
1315

1416
NEW_DIVISION = ("""\
1517
from __future__ import division
1618
1 / 2
19+
a /= 3
1720
""",
1821
"""\
1922
from __future__ import division
2023
1 / 2
24+
a /= 3
2125
""")
2226

2327

0 commit comments

Comments
 (0)