From 4332803bd1b9093d372a2ccf55c4af5ec45eda9a Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Mon, 3 Sep 2018 16:15:50 -0400 Subject: [PATCH 1/2] Fix #113 --- src/libfuturize/fixer_util.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libfuturize/fixer_util.py b/src/libfuturize/fixer_util.py index ce1e9753..a10184c7 100644 --- a/src/libfuturize/fixer_util.py +++ b/src/libfuturize/fixer_util.py @@ -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 @@ -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: From 359b749d808a248073919047fdb58bb0d8dcf515 Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Mon, 10 Sep 2018 00:44:43 -0400 Subject: [PATCH 2/2] Add test for #113 --- tests/test_future/test_futurize.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_future/test_futurize.py b/tests/test_future/test_futurize.py index f3fe0b84..d46f9bc4 100644 --- a/tests/test_future/test_futurize.py +++ b/tests/test_future/test_futurize.py @@ -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