Martin Panter added the comment:

This would be hard to get right, but maybe not impossible. If the frame is 
suspended, and will do special handling of GeneratorExit, a ResourceWarning 
would be nice in most cases. But if the frame will not catch any exception, 
there should be no ResourceWarning. I think this is the big difference between 
mygen() and Victor’s generator expression:

gen = (2**i for i in itertools.count())
next(gen)  # Generator suspended but won’t catch any exception
del gen  # Like deleting a plain iterator; no ResourceWarning expected

One more complication: If the frame is suspended at something like “yield from 
open(fname)”, it should trigger a ResourceWarning, because GeneratorExit would 
cause the file’s close() method to be called. But if “yield from” is calling a 
simpler generator-iterator with nothing to clean up, it should not emit a 
ResourceWarning.

----------
nosy: +martin.panter

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

Reply via email to