Skip to content

Commit

Permalink
Merge pull request #79 from brettcannon/fix_long_call
Browse files Browse the repository at this point in the history
Fix references to 'long'
  • Loading branch information
takluyver committed Sep 23, 2014
2 parents e5b9d5d + 6f98f5b commit 9b0e66d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libmodernize/fixes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'lib2to3.fixes.fix_funcattrs',
'lib2to3.fixes.fix_has_key',
'lib2to3.fixes.fix_idioms',
'lib2to3.fixes.fix_long',
'lib2to3.fixes.fix_methodattrs',
'lib2to3.fixes.fix_ne',
'lib2to3.fixes.fix_numliterals',
Expand All @@ -32,6 +33,7 @@
'libmodernize.fixes.fix_filter',
'libmodernize.fixes.fix_imports_six',
'libmodernize.fixes.fix_input_six',
'libmodernize.fixes.fix_int_long_tuple',
'libmodernize.fixes.fix_map',
'libmodernize.fixes.fix_metaclass',
'libmodernize.fixes.fix_raise_six',
Expand Down
25 changes: 25 additions & 0 deletions libmodernize/fixes/fix_int_long_tuple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import absolute_import

from lib2to3 import fixer_base
from lib2to3 import fixer_util


class FixIntLongTuple(fixer_base.BaseFix):

run_order = 4 # Must run before fix_long.

PATTERN = """
pair=atom < '(' testlist_gexp < (
('int' ',' 'long') |
('long' ',' 'int')
) > ')' >
"""

def transform(self, node, results):
if 'name' in results:
name = results['name']
name.replace(fixer_util.Name('int', prefix=name.prefix))

This comment has been minimized.

Copy link
@daira

daira Sep 29, 2014

Contributor

This branch isn't covered by tests (https://coveralls.io/files/301713367). What is it for? The pattern seems to only match a pair.

This comment has been minimized.

Copy link
@takluyver

takluyver Sep 29, 2014

Author Contributor

I guess it's a leftover from when this fixer handled the name long as well. In which case it can safely be removed.

This comment has been minimized.

Copy link
@daira

daira Sep 29, 2014

Contributor

Removed in [2d6284f].

else:
fixer_util.touch_import(None, 'six', node)
pair = results['pair']
pair.replace(fixer_util.Name('six.integer_types', prefix=pair.prefix))
25 changes: 25 additions & 0 deletions tests/test_fix_int_long_tuple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import absolute_import

from utils import check_on_input


INT_LONG_ISINSTANCE = ("""\
isinstance(1, (int, long))
""", """\
import six
isinstance(1, six.integer_types)
""")

LONG_INT_ISINSTANCE = ("""\
isinstance(1, (long, int))
""", """\
import six
isinstance(1, six.integer_types)
""")


def test_int_long_isinstance():
check_on_input(*INT_LONG_ISINSTANCE)

def test_long_int_isinstance():
check_on_input(*LONG_INT_ISINSTANCE)

0 comments on commit 9b0e66d

Please sign in to comment.