Issue 12613: itertools fixer fails - Python tracker

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
process
Status: closed Resolution: wont fix
Dependencies: Superseder: Close 2to3 issues and list them here
View: 45544
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 2022-04-11 14:57 by admin. This issue is now closed.

Files
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:

    izip().next()

This gets converted to:

    next(izip())

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
     matching.

  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.