[Python-ideas] PEP draft: context variables

Nathaniel Smith njs at pobox.com
Sat Oct 7 17:16:48 EDT 2017


On Oct 7, 2017 12:20, "Koos Zevenhoven" <k7hoven at gmail.com> wrote:


​Unfortunately, we actually need a third kind of generator semantics,
something like this:

@​contextvars.caller_context
def genfunc():
    assert cvar.value is the_value
    yield
    assert cvar.value is the_value

with cvar.assign(the_value):
    gen = genfunc()

next(gen)

with cvar.assign(1234567890):
    try:
        next(gen)
    except StopIteration:
        pass

Nick, Yury and I (and Nathaniel, Guido, Jim, ...?) somehow just narrowly
missed the reasons for this in discussions related to PEP 550. Perhaps
because we had mostly been looking at it from an async angle.


That's certainly a semantics that one can write down (and it's what the
very first version of PEP 550 did), but why do you say it's needed? What
are these reasons that were missed? Do you have a use case?

-n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171007/0c09d80f/attachment.html>


More information about the Python-ideas mailing list