<div dir="auto">By default, threading.local raises an AttributeError (unless you subclass it.)  Similar to that and to NameErrors, I think it's a good idea for ContextVars to raise a LookupError if a variable was not explicitly set.</div><div dir="auto"><br></div><div dir="auto">Yury</div><div dir="auto"><br></div><div><br><div class="gmail_quote"><div>On Tue, Jan 9, 2018 at 7:15 PM Victor Stinner <<a href="mailto:victor.stinner@gmail.com">victor.stinner@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">2018-01-09 12:41 GMT+01:00 Yury Selivanov <<a href="mailto:yselivanov.ml@gmail.com" target="_blank">yselivanov.ml@gmail.com</a>>:<br>
> But I'd be -1 on making all ContextVars have a None default<br>
> (effectively have a "ContextVar.get(default=None)" signature. This<br>
> would be a very loose semantics in my opinion.<br>
<br>
Why do you think that it's a loose semantics? For me<br>
ContextVar/Context are similar to Python namespaces and thread local<br>
storage.<br>
<br>
To "declare" a variable in a Python namespace, you have to set it:<br>
"global x" doesn't create a variable, only "x = None".<br>
<br>
It's not possible to define a thread local variable without specifying<br>
a "default" value neither.<br>
<br>
Victor<br>
</blockquote></div></div>