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: Bug in equivalent code for itertools.izip_longest
Type: Stage:
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: agforsyth, docs@python, eli.bendersky, georg.brandl, rhettinger
Priority: normal Keywords:

Created on 2011-09-18 04:55 by eli.bendersky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg144228 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-09-18 04:55
Regarding the sample code in: http://docs.python.org/library/itertools#itertools.izip_longest

If an IndexError is raised inside an iterator in the "equivalent" code
from the docs, the generator stops and the error is swallowed.

If an IndexError is raised inside an iterator in the
"izip_longest_next" code in CPython's "Modules/itertoolsmodule.c", the
generator stops and the error propagates.

---

Reported by Adam Forsyth on the docs mailing list. More details in this SO discussion: http://stackoverflow.com/questions/7392902/izip-longest-in-itertools-how-does-rasing-indexerror-inside-the-iterator-work
msg144229 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-09-18 05:36
I had forwarded this to Raymond, and he replied:

The itertools module code is correct.
The "equivalent" is only approximately correct 
I don't consider it to be a bug -- it is an implementation detail in an illustration.
msg144231 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-09-18 05:50
What about at least documenting it? Since a real user ran into this and reported it as a problem, I think it would make sense to make the discrepancy explicit.

Alternatively a generalized note can be added to the documentation of itertools stating that the "equivalent" code samples are only approximate and differ in small details from the real implementations.
msg144232 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-09-18 05:53
Well, this is for Raymond to decide.
msg148749 - (view) Author: Adam Forsyth (agforsyth) Date: 2011-12-02 01:05
This is marked as "wont fix" but has been fixed, the resolution should be changed.
msg148751 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-12-02 03:33
Yep, it appears that Raymond has fixed this in changeset b0065b9087ef
History
Date User Action Args
2022-04-11 14:57:21adminsetgithub: 57212
2011-12-02 03:33:06eli.benderskysetresolution: wont fix -> fixed
messages: + msg148751
2011-12-02 01:05:11agforsythsetnosy: + agforsyth
messages: + msg148749
2011-09-18 05:53:07georg.brandlsetnosy: + rhettinger
messages: + msg144232
2011-09-18 05:50:07eli.benderskysetmessages: + msg144231
2011-09-18 05:36:06georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg144229

resolution: wont fix
2011-09-18 04:55:23eli.benderskycreate