[Python-Dev] PEP 567 v2

Victor Stinner victor.stinner at gmail.com
Thu Dec 28 18:48:00 EST 2017


NLe 28 déc. 2017 11:20 AM, "Nathaniel Smith" <njs at pobox.com> a écrit :

On Thu, Dec 28, 2017 at 1:51 AM, Victor Stinner
<victor.stinner at gmail.com> wrote:
> var = ContextVar('var', default=42)
>
> and:
>
> var = ContextVar('var')
> var.set (42)
>
> behaves the same, no?

No, they're different. The second sets the value in the current
context. The first sets the value in all contexts that currently
exist, and all empty contexts created in the future.


Oh, that's an important information. In this case, "default" is the best
name.

The PEP may be more explicit about the effect on all contexts. Proposition
of documentation:

"The optional *default* parameter is the default value in all contexts. If the
variable is not set in the current context, it is returned by by
context[var_name] and by var.get(), when get() is called without the
default parameter."

Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171229/329a0b72/attachment.html>


More information about the Python-Dev mailing list