Skip to content

Commit 1ee00e7

Browse files
committed
Update fixers invoked by pasteurize --all-imports
1 parent 277a779 commit 1ee00e7

File tree

7 files changed

+24
-25
lines changed

7 files changed

+24
-25
lines changed

docs/futurize.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ The complete set of fixers applied by ``futurize --stage1`` is:
154154
libfuturize.fixes.fix_next_call
155155
libfuturize.fixes.fix_print_with_import
156156
libfuturize.fixes.fix_raise
157-
libfuturize.fixes.fix_order___future__imports
158157
159158
160159
Not applied:
@@ -298,7 +297,6 @@ A complete list of fixers applied in Stage 2 is::
298297
libfuturize.fixes.fix_metaclass
299298
libpasteurize.fixes.fix_newstyle
300299
libfuturize.fixes.fix_object
301-
libfuturize.fixes.fix_order___future__imports
302300
libfuturize.fixes.fix_unicode_keep_u
303301
libfuturize.fixes.fix_xrange_with_import
304302

libfuturize/fixer_util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ def touch_import_top(package, name_to_import, node):
306306
if does_tree_import(package, name_to_import, root):
307307
return
308308

309+
# Ideally, we would look for whether futurize --all-imports has been run,
310+
# as indicated by the presence of ``from future.builtins import (ascii, ...,
311+
# zip)`` -- and, if it has, we wouldn't import the name again.
312+
309313
# Look for __future__ imports and insert below them
310314
found = False
311315
for name in ['absolute_import', 'division', 'print_function',

libfuturize/fixes/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
# the ``next`` method to ``__next__``.
7676
'libfuturize.fixes.fix_print_with_import',
7777
'libfuturize.fixes.fix_raise',
78-
'libfuturize.fixes.fix_order___future__imports', # TODO: consolidate to a single line to simplify testing
78+
# 'libfuturize.fixes.fix_order___future__imports', # TODO: consolidate to a single line to simplify testing
7979
])
8080

8181
libfuturize_fix_names_stage2 = set([
@@ -89,7 +89,7 @@
8989
'libfuturize.fixes.fix_metaclass',
9090
'libpasteurize.fixes.fix_newstyle',
9191
'libfuturize.fixes.fix_object',
92-
'libfuturize.fixes.fix_order___future__imports', # TODO: consolidate to a single line to simplify testing
92+
# 'libfuturize.fixes.fix_order___future__imports', # TODO: consolidate to a single line to simplify testing
9393
'libfuturize.fixes.fix_unicode_keep_u',
9494
# 'libfuturize.fixes.fix_unicode_literals_import',
9595
'libfuturize.fixes.fix_xrange_with_import', # custom one because of a bug with Py3.3's lib2to3

libfuturize/main.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,6 @@ def main(args=None):
210210

211211
unwanted_fixes = set(fixer_pkg + ".fix_" + fix for fix in options.nofix)
212212

213-
# The 'all-imports' option forces adding all __future__ imports and "from
214-
# future import standard_library", even if they don't seem necessary for
215-
# the current state of each module. (This can simplify testing, and can
216-
# reduce the need to think about Py2 compatibility when editing the code
217-
# further.)
218213
extra_fixes = set()
219214
if options.all_imports:
220215
if options.stage1:

libpasteurize/fixes/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
# The original set of these fixes comes from lib3to2 (https://bitbucket.org/amentajo/lib3to2):
55
fix_names = set([
6-
'libfuturize.fixes.fix_add__future__imports', # from __future__ import absolute_import etc. on separate lines
6+
'libpasteurize.fixes.fix_add_all__future__imports', # from __future__ import absolute_import etc. on separate lines
77
'libpasteurize.fixes.fix_add_future_standard_library_import', # we force adding this import for now, even if it doesn't seem necessary to the fix_future_standard_library fixer, for ease of testing
8-
'libfuturize.fixes.fix_order___future__imports', # consolidates to a single line to simplify testing
8+
# 'libfuturize.fixes.fix_order___future__imports', # consolidates to a single line to simplify testing -- UNFINISHED
99
'libpasteurize.fixes.fix_future_builtins', # adds "from future.builtins import *"
1010
'libfuturize.fixes.fix_future_standard_library', # adds "from future import standard_library"
1111

libpasteurize/fixes/fix_add_all_future_builtins.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ def transform(self, node, results):
3030
range, round, str, super, zip)"""
3131
touch_import_top(u'future.builtins', import_str, node)
3232

33+
# builtins = """ascii bytes chr dict filter hex input
34+
# int list map next object oct open pow
35+
# range round str super zip"""
36+
# for builtin in sorted(builtins.split(), reverse=True):
37+
# touch_import_top(u'future.builtins', builtin, node)
38+

libpasteurize/main.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
Python 3 with ``pasteurize`` as they are when converting from Python 2 with
2929
``futurize``.
3030
31+
The --all-imports option forces adding all ``__future__`` imports,
32+
``future.builtins`` imports, and standard library hooks, even if they don't
33+
seem necessary for the current state of each module. (This can simplify
34+
testing, and can reduce the need to think about Py2 compatibility when editing
35+
the code further.)
36+
3137
"""
3238

3339
from __future__ import (absolute_import, print_function, unicode_literals)
@@ -115,22 +121,12 @@ def main(args=None):
115121
# Initialize the refactoring tool
116122
unwanted_fixes = set(fixer_pkg + ".fix_" + fix for fix in options.nofix)
117123

118-
# The 'all-imports' option forces adding all imports __future__ and "from
119-
# future import standard_library", even if they don't seem necessary for
120-
# the current state of each module. (This can simplify testing, and can
121-
# reduce the need to think about Py2 compatibility when editing the code
122-
# further.)
123124
extra_fixes = set()
124125
if options.all_imports:
125-
prefix = 'libfuturize.fixes.'
126-
if options.stage1:
127-
extra_fixes.add(prefix +
128-
'fix_add__future__imports_except_unicode_literals')
129-
else:
130-
# In case the user hasn't run stage1 for some reason:
131-
extra_fixes.add(prefix + 'fix_add__future__imports')
132-
extra_fixes.add(prefix + 'fix_add_future_standard_library_import')
133-
extra_fixes.add(prefix + 'fix_add_all_future_builtins')
126+
prefix = 'libpasteurize.fixes.'
127+
extra_fixes.add(prefix + 'fix_add_all__future__imports')
128+
extra_fixes.add(prefix + 'fix_add_future_standard_library_import')
129+
extra_fixes.add(prefix + 'fix_add_all_future_builtins')
134130

135131
fixer_names = avail_fixes | extra_fixes - unwanted_fixes
136132

0 commit comments

Comments
 (0)