Skip to content

Commit 9b0e66d

Browse files
committed
Merge pull request #79 from brettcannon/fix_long_call
Fix references to 'long'
2 parents e5b9d5d + 6f98f5b commit 9b0e66d

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

libmodernize/fixes/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
'lib2to3.fixes.fix_funcattrs',
99
'lib2to3.fixes.fix_has_key',
1010
'lib2to3.fixes.fix_idioms',
11+
'lib2to3.fixes.fix_long',
1112
'lib2to3.fixes.fix_methodattrs',
1213
'lib2to3.fixes.fix_ne',
1314
'lib2to3.fixes.fix_numliterals',
@@ -32,6 +33,7 @@
3233
'libmodernize.fixes.fix_filter',
3334
'libmodernize.fixes.fix_imports_six',
3435
'libmodernize.fixes.fix_input_six',
36+
'libmodernize.fixes.fix_int_long_tuple',
3537
'libmodernize.fixes.fix_map',
3638
'libmodernize.fixes.fix_metaclass',
3739
'libmodernize.fixes.fix_raise_six',
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from __future__ import absolute_import
2+
3+
from lib2to3 import fixer_base
4+
from lib2to3 import fixer_util
5+
6+
7+
class FixIntLongTuple(fixer_base.BaseFix):
8+
9+
run_order = 4 # Must run before fix_long.
10+
11+
PATTERN = """
12+
pair=atom < '(' testlist_gexp < (
13+
('int' ',' 'long') |
14+
('long' ',' 'int')
15+
) > ')' >
16+
"""
17+
18+
def transform(self, node, results):
19+
if 'name' in results:
20+
name = results['name']
21+
name.replace(fixer_util.Name('int', prefix=name.prefix))
22+
else:
23+
fixer_util.touch_import(None, 'six', node)
24+
pair = results['pair']
25+
pair.replace(fixer_util.Name('six.integer_types', prefix=pair.prefix))

tests/test_fix_int_long_tuple.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from __future__ import absolute_import
2+
3+
from utils import check_on_input
4+
5+
6+
INT_LONG_ISINSTANCE = ("""\
7+
isinstance(1, (int, long))
8+
""", """\
9+
import six
10+
isinstance(1, six.integer_types)
11+
""")
12+
13+
LONG_INT_ISINSTANCE = ("""\
14+
isinstance(1, (long, int))
15+
""", """\
16+
import six
17+
isinstance(1, six.integer_types)
18+
""")
19+
20+
21+
def test_int_long_isinstance():
22+
check_on_input(*INT_LONG_ISINSTANCE)
23+
24+
def test_long_int_isinstance():
25+
check_on_input(*LONG_INT_ISINSTANCE)

0 commit comments

Comments
 (0)