[Python-ideas] PEP draft: context variables
k7hoven at gmail.com
Tue Oct 10 12:34:44 EDT 2017
On Tue, Oct 10, 2017 at 3:42 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 10 October 2017 at 22:34, Koos Zevenhoven <k7hoven at gmail.com> wrote:
>> Really, it was my mistake to ever make you think that
>> context_var.assign(42).__enter__() can be compared to .set(42) in PEP
>> 550. I'll say it once more: PEP 555 context arguments have no equivalent of
>> the PEP-550 .set(..).
> Then your alternate PEP can't work, since it won't be useful to extension
Maybe this helps:
* PEP 550 is based on var.set(..), but you will then implement context
managers on top of that.
* PEP 555 is based context managers, but you can implement a var.set(..)
on top of that if you really need it.
> Context managers are merely syntactic sugar for try/finally statements, so
> you can't wave your hands and say a context manager is the only supported
> API: you *have* to break the semantics down and explain what the
> try/finally equivalent looks like.
Is this what you're asking?
assi = cvar.assign(value)
# do stuff involving cvar.value
As written in the PEP, these functions would have C equivalents. But most C
extensions will probably only need cvar.value, and the assignment contexts
will be entered from Python.
+ Koos Zevenhoven + http://twitter.com/k7hoven +
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas