Author serhiy.storchaka
Recipients gvanrossum, miss-islington, serhiy.storchaka
Date 2021-06-23.10:07:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1624442859.41.0.329248432364.issue44482@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-06-23 10:07:39serhiy.storchakasetrecipients: + serhiy.storchaka, gvanrossum, miss-islington
2021-06-23 10:07:39serhiy.storchakasetmessageid: <1624442859.41.0.329248432364.issue44482@roundup.psfhosted.org>
2021-06-23 10:07:39serhiy.storchakalinkissue44482 messages
2021-06-23 10:07:39serhiy.storchakacreate