This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: 2to3 incorrectly handles multi-line imports from __future__
Type: Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder: Close 2to3 issues and list them here
View: 45544
Assigned To: Nosy List: Arfrever, benjamin.peterson, eric.araujo, jdekloe, lunaryorn
Priority: normal Keywords:

Created on 2011-08-31 21:57 by Arfrever, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg143283 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2011-08-31 21:57
$ 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
msg143418 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-09-02 17:06
I don’t understand what the bug is.
msg143425 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2011-09-02 17:52
If import from __future__ is written in multiple lines, then a parser internally used by 2to3 recognizes only the first line. (However Python interpreter properly supports multi-line imports from __future__.)

test1.py contains multi-line import from __future__.
test2.py contains single-line import from __future__.
2to3 properly handles test2.py and improperly handles test1.py.
msg143429 - (view) Author: (lunaryorn) Date: 2011-09-02 18:21
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.
msg253129 - (view) Author: Jos de Kloe (jdekloe) Date: 2015-10-17 14:33
still having this issue with 2to3 from python-tools-2.7.8-11 as packaged by Fedora 21.
Any progress since 2011?
History
Date User Action Args
2022-04-11 14:57:21adminsetgithub: 57082
2021-10-20 22:46:23iritkatrielsetstatus: open -> closed
superseder: Close 2to3 issues and list them here
resolution: wont fix
stage: resolved
2015-10-17 14:33:28jdekloesetnosy: + jdekloe
messages: + msg253129
2011-09-02 18:21:01lunaryornsetmessages: + msg143429
2011-09-02 17:52:25Arfreversetmessages: + msg143425
2011-09-02 17:06:42eric.araujosetnosy: + eric.araujo
messages: + msg143418
2011-09-01 11:38:03lunaryornsetnosy: + lunaryorn
2011-08-31 21:57:20Arfrevercreate