Nathaniel Smith added the comment:

It does make sense to skip emitting a warning if there's no try or with block 
active.

Don't we already have the ability to check for this, though, without any 
extensions to the frame or code objects? That's what the public 
PyGen_NeedsFinalizing does, right? It's implemented as a for loop over the 
frame's block stack, which in most cases should be extremely small, so the 
performance cost of running this from generator.__del__ seems likely to be 
minimal.

(I think currently the implementation is not *quite* correct if there's a 
'yield from' active – in most cases it won't much matter because if A is 
yielding from B and A is collected, then B will probably be collected a moment 
later and have its own __del__ called. But this is not *quite* the same as what 
should happen, which is that collecting A should immediately call B.close(), 
which in principle might do something arbitrarily different than B.__del__. But 
adding a check for whether a 'yield from' is active would be pretty trivial.)

----------

_______________________________________
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