Skip to content

Commit 5021b64

Browse files
committed
Merge pull request #117 from takluyver/future-import-paren
Handle parenthesised future imports
2 parents 2400d08 + 1457b72 commit 5021b64

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

libmodernize/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ def check_future_import(node):
1919
node.children[1].type == token.NAME and
2020
node.children[1].value == u'__future__'):
2121
return set()
22-
node = node.children[3]
22+
23+
if node.children[3].type == token.LPAR:
24+
# from __future__ import (..
25+
node = node.children[4]
26+
else:
27+
# from __future__ import ...
28+
node = node.children[3]
2329
# now node is the import_as_name[s]
30+
2431
# print(python_grammar.number2symbol[node.type])
2532
if node.type == syms.import_as_names:
2633
result = set()

tests/test_future_behaviour.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,22 @@ def test_problematic_file():
111111
print("abc")
112112
""")
113113

114+
FUTURE_IMPORT_PAREN = ("""\
115+
from __future__ import (absolute_import, division, print_function)
116+
unicode("abc")
117+
""", """\
118+
from __future__ import (absolute_import, division, print_function)
119+
import six
120+
six.text_type("abc")
121+
"""
122+
)
123+
114124
def test_future_import_as():
115125
check_on_input(*FUTURE_IMPORT_AS)
116126

117127
def test_future_import_as_multiple():
118128
check_on_input(*FUTURE_IMPORT_AS_MULTIPLE)
129+
130+
def test_future_import_paren():
131+
check_on_input(*FUTURE_IMPORT_PAREN)
132+

0 commit comments

Comments
 (0)