Skip to content

Commit

Permalink
Merge pull request #357 from flaviut/master
Browse files Browse the repository at this point in the history
Fix #113
  • Loading branch information
jmadler authored Sep 10, 2018
2 parents 39a066e + 359b749 commit 7499e98
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libfuturize/fixer_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def future_import(feature, node):
# Is it a shebang or encoding line?
if is_shebang_comment(node) or is_encoding_comment(node):
shebang_encoding_idx = idx
continue
if is_docstring(node):
# skip over docstring
continue
Expand Down Expand Up @@ -443,7 +444,10 @@ def check_future_import(node):
hasattr(node.children[1], 'value') and
node.children[1].value == u'__future__'):
return set()
node = node.children[3]
if node.children[3].type == token.LPAR:
node = node.children[4]
else:
node = node.children[3]
# now node is the import_as_name[s]
# print(python_grammar.number2symbol[node.type]) # breaks sometimes
if node.type == syms.import_as_names:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_future/test_futurize.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ def test_encoding_comments_kept_at_top(self):
"""
self.convert_check(before, after)

def test_multiline_future_import(self):
"""
Issue #113: don't crash if a future import has multiple lines
"""
text = """
from __future__ import (
division
)
"""
self.convert(text)

def test_shebang_blank_with_future_division_import(self):
"""
Issue #43: Is shebang line preserved as the first
Expand Down

0 comments on commit 7499e98

Please sign in to comment.