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

On Thu, Dec 28, 2017 at 1:51 AM, Victor Stinner
<victor.stin...@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
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to