Skip to content

Commit 277a779

Browse files
committed
Update fixers invoked by futurize --all-imports
1 parent 205a19c commit 277a779

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

libfuturize/main.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@
5353
All imports
5454
-----------
5555
56-
The --all-imports option forces adding all ``__future__`` imports and ``from
57-
future import standard_library``, even if they don't seem necessary for
58-
the current state of each module. (This can simplify testing, and can
59-
reduce the need to think about Py2 compatibility when editing the code
60-
further.)
56+
The --all-imports option forces adding all ``__future__`` imports,
57+
``future.builtins`` imports, and standard library hooks, even if they don't
58+
seem necessary for the current state of each module. (This can simplify
59+
testing, and can reduce the need to think about Py2 compatibility when editing
60+
the code further.)
6161
6262
"""
6363

@@ -217,13 +217,14 @@ def main(args=None):
217217
# further.)
218218
extra_fixes = set()
219219
if options.all_imports:
220-
prefix = 'libfuturize.fixes.'
221220
if options.stage1:
221+
prefix = 'libfuturize.fixes.'
222222
extra_fixes.add(prefix +
223223
'fix_add__future__imports_except_unicode_literals')
224224
else:
225225
# In case the user hasn't run stage1 for some reason:
226-
extra_fixes.add(prefix + 'fix_add__future__imports')
226+
prefix = 'libpasteurize.fixes.'
227+
extra_fixes.add(prefix + 'fix_add_all__future__imports')
227228
extra_fixes.add(prefix + 'fix_add_future_standard_library_import')
228229
extra_fixes.add(prefix + 'fix_add_all_future_builtins')
229230
explicit = set()

libfuturize/fixes/fix_add__future__imports.py renamed to libpasteurize/fixes/fix_add_all__future__imports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from lib2to3 import fixer_base
1313
from libfuturize.fixer_util import future_import
1414

15-
class FixAddFutureImports(fixer_base.BaseFix):
15+
class FixAddAllFutureImports(fixer_base.BaseFix):
1616
BM_compatible = True
1717
PATTERN = "file_input"
1818
run_order = 1
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
For the ``future`` package.
3+
4+
Adds this import line::
5+
6+
from future.builtins import (ascii, bytes, chr, dict, filter, hex, input,
7+
int, list, map, next, object, oct, open, pow,
8+
range, round, str, super, zip)
9+
10+
to a module, irrespective of whether each definition is used.
11+
12+
Adds these imports after any other imports (in an initial block of them).
13+
"""
14+
15+
from __future__ import unicode_literals
16+
17+
from lib2to3 import fixer_base
18+
19+
from libfuturize.fixer_util import touch_import_top
20+
21+
22+
class FixAddAllFutureBuiltins(fixer_base.BaseFix):
23+
BM_compatible = True
24+
PATTERN = "file_input"
25+
run_order = 1
26+
27+
def transform(self, node, results):
28+
import_str = """(ascii, bytes, chr, dict, filter, hex, input,
29+
int, list, map, next, object, oct, open, pow,
30+
range, round, str, super, zip)"""
31+
touch_import_top(u'future.builtins', import_str, node)
32+

0 commit comments

Comments
 (0)