homepage

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 zip fixer doesn't fix for loops.
Type: behavior Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Close 2to3 issues and list them here
View: 45544
Assigned To: Nosy List: RobertG, benjamin.peterson, drj, peter.otten
Priority: normal Keywords:

Created on 2014年02月23日 11:11 by drj, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Messages (3)
msg211989 - (view) Author: David Jones (drj) * Date: 2014年02月23日 11:11
Consider the following code:
for z in zip([1]):pass
2to3 does not convert the zip in this code to list(zip(...)); it does not change this code at all.
That can be an (obscure) bug because the zip in Python 2 has different semantics from the zip in Python 3.
The output of this program
from __future__ import print_function
S = []
def l(c):
 for i in [0,1]:
 S.append(c)
 yield i
 S.append(c.upper())
la = l('a')
lb = l('b')
for a,b in zip(la, lb):
 S.append("#")
print(''.join(S))
is different in Python 2 and Python 3 (when converted with 2to3, which doesn't change the program).
In Python 2 the output is:
ababA##
In Python 3 the output is:
ab#ab#A
Obviously this example is somewhat contrived, but I have a non-contrived example involving decoding PNG images (if anyone is interested).
msg211991 - (view) Author: Peter Otten (peter.otten) * Date: 2014年02月23日 11:45
Hm, I would expect that in 99 times out of 100 the extra list(...) would be removed in a manual step following the automated conversion.
I'd really like to see the non-contrived example with a justified use of this evil side effect ;)
msg227772 - (view) Author: RobertG (RobertG) Date: 2014年09月28日 18:55
As far as a non contrived example, see http://bugs.python.org/issue21628, which was marked as a duplicate of this bug.
This bug is the main thing preventing me from using 2to3, so I think it is a real issue.
History
Date User Action Args
2022年04月11日 14:57:59adminsetgithub: 64941
2021年10月20日 22:45:21iritkatrielsetstatus: open -> closed
superseder: Close 2to3 issues and list them here
resolution: duplicate
stage: resolved
2014年09月28日 18:55:56RobertGsetmessages: + msg227772
2014年06月02日 11:15:24berker.peksagsetnosy: + benjamin.peterson, RobertG

versions: + Python 2.7, Python 3.4, Python 3.5, - Python 3.2
2014年06月02日 11:15:08berker.peksaglinkissue21628 superseder
2014年02月23日 11:45:19peter.ottensetnosy: + peter.otten
messages: + msg211991
2014年02月23日 11:11:47drjcreate

AltStyle によって変換されたページ (->オリジナル) /