[New-bugs-announce] [issue20742] 2to3 zip fixer doesn't fix for loops.

David Jones report at bugs.python.org
Sun Feb 23 12:11:47 CET 2014

New submission from David Jones:

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]:
    yield i

la = l('a')
lb = l('b')

for a,b in zip(la, lb):

is different in Python 2 and Python 3 (when converted with 2to3, which doesn't change the program).

In Python 2 the output is:


In Python 3 the output is:


Obviously this example is somewhat contrived, but I have a non-contrived example involving decoding PNG images (if anyone is interested).

components: 2to3 (2.x to 3.x conversion tool)
messages: 211989
nosy: drj
priority: normal
severity: normal
status: open
title: 2to3 zip fixer doesn't fix for loops.
type: behavior
versions: Python 3.2

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list