Title: itertools fixer fails
Type: behavior Stage: patch review
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.4, Python 3.5, Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Aaron.Meurer, VPeric, benjamin.peterson, eric.araujo, meador.inge, petri.lehtinen
Priority: high Keywords: needs review, patch

Created on 2011-07-22 16:49 by VPeric, last changed 2019-03-15 23:53 by BreamoreBoy.

File name Uploaded Description Edit
issue12613.patch meador.inge, 2011-08-11 04:13 Patch against 2to3 tip
Messages (4)
msg140897 - (view) Author: Vlada Peric (VPeric) Date: 2011-07-22 16:49
The itertools fixer (izip -> zip, among others), fails for the following code:

from itertools import izip
print msg % str(bool(symbol_swapped) and list(izip(*swap_dict).next()) or symbols)

It gets converted to:

print(msg % str(bool(symbol_swapped) and list(next(izip(*swap_dict))) or symbols))

(note how izip is still there)

I've worked aroudn this by introducing tmp = izip(...) and using that, but it'd be nice if 2to3 caught it by default.
msg141836 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2011-08-09 18:44
A smaller snippet to reproduce:


This gets converted to:


It seems to me that the pattern of the itertools fixer doesn't match to izip().something(), and thus this is skipped.
msg141893 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2011-08-11 04:13
I see two problems that cause the posted test cases to fail:

  1. The 'next' fixer runs before the 'itertools' fixer and strips
     out a 'power' node.  This keeps the 'itertools' fixer from

  2. The 'itertools' fixer does not handle any 'trailer' nodes after
     the itertool function application it is transforming.

I have fixed both of these issues in the attached patch.  Full test suite run; no regressions.
msg221605 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-26 14:52
The patch is small and looks clean to me.  Can someone take a look with a view to committing please, thanks.
Date User Action Args
2019-03-15 23:53:58BreamoreBoysetnosy: - BreamoreBoy
2014-06-26 15:23:07berker.peksagsetversions: + Python 3.5, - Python 3.2, Python 3.3
2014-06-26 14:52:17BreamoreBoysetnosy: + BreamoreBoy
messages: + msg221605
2013-01-04 17:37:03serhiy.storchakasetkeywords: + needs review
versions: + Python 3.4
2011-08-11 04:13:20meador.ingesetfiles: + issue12613.patch
messages: + msg141893

keywords: + patch
type: behavior
stage: needs patch -> patch review
2011-08-10 20:29:18meador.ingesetnosy: + meador.inge
2011-08-09 18:44:21petri.lehtinensetmessages: + msg141836
2011-08-09 18:20:51petri.lehtinensetnosy: + petri.lehtinen
2011-07-25 23:06:18Aaron.Meurersetnosy: + Aaron.Meurer
2011-07-23 02:52:12rhettingersetpriority: normal -> high
2011-07-22 21:19:04eric.araujosetnosy: + eric.araujo
stage: needs patch

versions: + Python 3.3
2011-07-22 16:56:09vstinnersetnosy: + benjamin.peterson
2011-07-22 16:49:31VPericcreate