Ezio Melotti <ezio.melo...@gmail.com> added the comment:

a) that's true, even if the behavior makes sense (when the first generator ends 
there's no reason to see what's next in the second). Georg, do you think it 
should be documented?

b) if you want to be sure that some clean-up is executed you should use a 
try/finally in the generator. Relying on the number of elements of another 
generator used together with zip() seems very fragile to determine when/if a 
clean-up should be done (what if the other generator has a different number of 
elements? what if an exception is raised before it's fully consumed? what if 
you use the generator in for/while loop and break the loop before reaching the 
end? ...).

c) even if you consider it as a wart, changing it for zip() will break 
compatibility and it's against the language moratorium. This behavior is also 
useful if e.g. you have the generators g1 that yields 1 2 3, g2 that yields 4 5 
6, and g3 that yields a b c d e f and you want to first zip(g1, g3) and get 1a 
2b 3c and then continue with zip(g2, g3) and get 4d 5e 6f. Checking in the 
first zip() if g3 reached its end or not would mean consuming the 'd', and that 
would be a worse wart imho.

----------
nosy: +eric.araujo, georg.brandl

_______________________________________
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