Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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