Skip to content

Commit 9b0cff3

Browse files
committed
Revert futurize/pasteurize --all-imports --all-imports to add from future.builtins import *
This is instead of this explicit longhand form over multiple lines: from future.builtins import (ascii, ..., ..., zip) This fixes issue #101.
1 parent 1ee00e7 commit 9b0cff3

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

docs/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ imports deemed necessary.
642642
There is now an ``--all-imports`` option to the ``futurize`` script which
643643
gives the previous behaviour, which is to add all ``__future__`` imports
644644
and ``from future.builtins import *`` imports to every module. (This even
645-
applies to an empty ``__init__.py`` file.
645+
applies to an empty ``__init__.py`` file.)
646646

647647

648648
Looser type-checking for the backported ``str`` object

future/tests/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def convert_check(self, before, expected, stages=(1, 2), all_imports=False,
246246
else:
247247
headers = ''
248248

249-
self.compare(output, reformat_code(headers + expected),
249+
self.compare(output, headers + reformat_code(expected),
250250
ignore_imports=ignore_imports)
251251

252252
def unchanged(self, code, **kwargs):

future/tests/test_futurize.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,5 +1167,41 @@ def __truediv__(self, other):
11671167
self.convert_check(before, after)
11681168

11691169

1170+
class TestFuturizeAllImports(CodeHandler):
1171+
"""
1172+
Tests "futurize --all-imports".
1173+
"""
1174+
def test_all_imports(self):
1175+
before = """
1176+
import math
1177+
import os
1178+
l = range(10)
1179+
assert isinstance(l, list)
1180+
print 'Hello'
1181+
for i in xrange(100):
1182+
pass
1183+
print('Hello')
1184+
"""
1185+
after = """
1186+
from __future__ import unicode_literals
1187+
from __future__ import print_function
1188+
from __future__ import division
1189+
from __future__ import absolute_import
1190+
from future import standard_library
1191+
standard_library.install_hooks()
1192+
from future.builtins import range
1193+
from future.builtins import *
1194+
import math
1195+
import os
1196+
l = list(range(10))
1197+
assert isinstance(l, list)
1198+
print('Hello')
1199+
for i in range(100):
1200+
pass
1201+
print('Hello')
1202+
"""
1203+
self.convert_check(before, after, all_imports=True)
1204+
1205+
11701206
if __name__ == '__main__':
11711207
unittest.main()

libpasteurize/fixes/fix_add_all_future_builtins.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class FixAddAllFutureBuiltins(fixer_base.BaseFix):
2525
run_order = 1
2626

2727
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)
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', '*', node)
3232

3333
# builtins = """ascii bytes chr dict filter hex input
3434
# int list map next object oct open pow

0 commit comments

Comments
 (0)