Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

Yes. I added you Guido to the nosy list to attract attention to a general 
issue. If the generator owns resources, it should be guaranteed closed. Since 
generator do not support the context manager protocol, we need to use closing().

Using generators is common in the code on my work, so I am going to revise all 
uses of resource-owning generators in my work code, in the stdlib and in common 
libraries like aiohttp.

May be we will add a decorator for generator functions which would add support 
of the context manager protocol. Or make generator objects supporting the 
context manager protocol by default. Or make the with statement fall back to 
the close() method by default. Or even add special syntax shortcut for 
combining "with" and "for" if this idiom will be common enough.

----------

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

Reply via email to