New submission from Greg Kochanski <g...@kochanski.org>:

When you have a generator as an argument to zip(), code after the last yield 
statement may not get executed.  The problem is that zip() stops after it gets 
_one_ exception, i.e. when just one of the generators has finished.

As a result, if there were any important clean-up code at the end of a 
generator, it will not be executed.   Caches may not get flushed, et cetera.

At the least, this is a documentation bug that needs to be pointed out in both 
zip() and the definition of a generator().  More realistically, it is a severe 
wart on the language, because it violates the programmer's reasonable 
expectation that a generator executes until it falls off the end of the 
function.  It means that a generator becomes conceptually nasty: you cannot 
predict what it will do based just on an inspection of the code and the code it 
calls.

Likely, the same behavior happens in itertools, too.

----------
components: None
files: bug312.py
messages: 128842
nosy: gpk-kochanski
priority: normal
severity: normal
status: open
title: Tails of generator get lost under zip()
type: behavior
versions: Python 2.6
Added file: http://bugs.python.org/file20794/bug312.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11248>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to