[Python-ideas] PEP draft: context variables

Koos Zevenhoven k7hoven at gmail.com
Tue Sep 5 09:53:52 EDT 2017


On Tue, Sep 5, 2017 at 1:20 AM, Oleg Broytman <phd at phdru.name> wrote:

> Hi!
>
> On Tue, Sep 05, 2017 at 12:50:35AM +0300, Koos Zevenhoven <
> k7hoven at gmail.com> wrote:
> >     cvar = contextvars.Var(default="the default value",
> >                            description="example context variable")
>
>    Why ``description`` and not ``doc``?
>
>
​Cause that's a nice thing to bikeshed about? In fact, I probably should
have left it out at this point.

Really, it's just to get a meaningful repr for the object and better error
messages, without any significance for the substance of the PEP. There are
also concepts in the PEP that don't have a name yet.



> >     with cvar.assign(new_value):
>
>    Why ``assign`` and not ``set``?
>

​To distinguish from typical set-operations (setattr, setitem), and from
sets and from settings. I would rather enter an "assignment context" than a
"set context" or "setting context".

One key point of this PEP is to promote defining context variable scopes on
a per-variable (and per-value) basis. I combined the variable and value
aspects in this concept of Assignment(variable, value) objects, which
define a context that one can enter and exit.


> > Each thread of the Python interpreter keeps its on stack of
>
>    "its own", I think.
>


​That's right, thanks.​

​––Koos​



-- 
+ Koos Zevenhoven + http://twitter.com/k7hoven +
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170905/881e7a12/attachment.html>


More information about the Python-ideas mailing list