◐ Shell
clean mode source ↗

Issue 12873: 2to3 incorrectly handles multi-line imports from __future__

$ cat test1.py
from __future__ import (absolute_import, division,
    print_function, unicode_literals)

print(1, 2)
$ cat test2.py
from __future__ import (absolute_import, division, print_function, unicode_literals)

print(1, 2)
$ python2.7 -c 'import test1'
1 2
$ python2.7 -c 'import test2'
1 2
$ 2to3 test1.py test2.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
RefactoringTool: Refactored test1.py
--- test1.py    (original)
+++ test1.py    (refactored)
@@ -1,4 +1,4 @@
 from __future__ import (absolute_import, division,
     print_function, unicode_literals)
 
-print(1, 2)
+print((1, 2))
RefactoringTool: Files that need to be modified:
RefactoringTool: test1.py
More precisely, the bug is, that 2to3 refactors the "print()" invocation in "test1.py" though it shouldn't because a "print_function" future import is present at the beginning of "test1.py".  The cross-check with "test2.py" shows that this is due to the multi-line future import in "test1.py" because the line-break in the import statement is the only difference between both files.