[Python-ideas] Make "yield" inside a with statement a SyntaxError
Yury Selivanov
yselivanov.ml at gmail.com
Wed Aug 8 13:41:42 EDT 2018
On Wed, Aug 8, 2018 at 12:28 PM Paul Moore <p.f.moore at gmail.com> wrote:
>
> 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?
To be even more precise, PEP 550 was designed to solve state handling
problem for both "await" (coroutines) and "yield" (generators). It was
rejected in favour of a more simplistic PEP 567 that solves it only
for coroutines.
PEP 568 was later drafted by Nathaniel. It applies PEP 550's ideas to
567 API/design to allow generators to have execution context too in
Python 3.8 or 3.9. The fate of PEP 568 is still undecided.
Yury
More information about the Python-ideas
mailing list