Skip to content

Commit a8c69fd

Browse files
committed
Fix addition for __future__.absolute_imports by fix_import
The 2to3 fixer makes no changes if it guesses that all the imports are absolute. We still want to add absolute_import in that case, however.
1 parent ac21860 commit a8c69fd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

libmodernize/fixes/fix_import.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22

33
from lib2to3.fixes import fix_import
4+
from lib2to3.fixer_util import syms
45
import libmodernize
56

67

@@ -11,8 +12,12 @@ class FixImport(fix_import.FixImport):
1112
run_order = 1
1213

1314
def transform(self, node, results):
14-
results = super(FixImport, self).transform(node, results)
15-
if results is None:
15+
if self.skip:
1616
return
17+
# We're not interested in __future__ imports here
18+
if node.type == syms.import_from and results['imp'].value == '__future__':
19+
return
20+
21+
# If there are any non-future imports, add absolute_import
1722
libmodernize.add_future(node, 'absolute_import')
18-
return results
23+
return super(FixImport, self).transform(node, results)

0 commit comments

Comments
 (0)