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

Paul Moore p.f.moore at gmail.com
Wed Aug 8 12:28:01 EDT 2018


On Wed, 8 Aug 2018 at 16:58, Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:
> Thinking about this some more: closing() can ensure finalisation but
> it is still generally bad to yield from a with block. Some context
> managers are designed to temporarily alter global state between
> __enter__ and __exit__ - this can be very confusing if you use them
> around a yield block.

Surely that's *precisely* what PEP 567 (Context Variables) was
designed to address?

Paul


More information about the Python-ideas mailing list