[Python-ideas] Make "yield" inside a with statement a SyntaxError

Chris Angelico rosuav at gmail.com
Wed Aug 8 03:31:45 EDT 2018


On Wed, Aug 8, 2018 at 5:05 PM, Barry Scott <barry at barrys-emacs.org> wrote:
> But so long as you do not leak the generator the file will be closed
> immediately after the loop as the ref count of the generater hits 0.

Technically that's not guaranteed (since refcounts aren't a language
feature), but if you're using this generator somewhere and want to be
able to force it to close its files, all you have to do is close the
generator.

ChrisA


More information about the Python-ideas mailing list