<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Dec 12, 2017 at 5:35 PM, Yury Selivanov <span dir="ltr"><<a href="mailto:yselivanov.ml@gmail.com" target="_blank">yselivanov.ml@gmail.com</a>></span> wrote:<span class="gmail-"></span><br><span class="gmail-"></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">
On Tue, Dec 12, 2017 at 6:49 PM, Victor Stinner<br>
<<a href="mailto:victor.stinner@gmail.com">victor.stinner@gmail.com</a>> wrote:<br>
> I like the overall idea and I prefer this PEP over PEP 550 since it's<br>
> shorter and easier to read :-)<br>
><br>
> Question: Is there an API to list all context variables?<br>
<br>
</span>Context implements abc.Mapping, so 'get_context().keys()' will give<br>
you a list of all ContextVars in the current context.<br></blockquote><div><br></div><div>This was hinted at in the PEP, but maybe an explicit example would be nice.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">
> Each get_context() call returns a new Context object. It may be worth<br>
> to mention it. I understand why, but it's surprising that "assert<br>
> get_context() is not get_context()" fails. Maybe it's a naming issue?<br>
> Maybe rename it to contextvars.context()?<br>
<br>
</span>I think the name is fine.  While get_context() will return a new instance<br>
every time you call it, those instances will have the same context<br>
variables/values in them, so I don't think it's a problem.<br></blockquote><div><br></div><div>I'm fine with this, but perhaps == should be supported so that those two are guaranteed to be considered equal? (Otherwise an awkward idiom to compare contexts using expensive dict() copies would be needed to properly compare two contexts for equality.)</div><div> <span class="gmail-"></span><br><span class="gmail-"></span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">
> At the first read, I understood that that ctx.run() creates a new<br>
> temporary context which is removed once ctx.run() returns.<br>
><br>
> Now I understand that context variable values are restored to their<br>
> previous values once run() completes. Am I right?<br>
<br>
</span>ctx.run(func) runs 'func' in the 'ctx' context.  Any changes to<br>
ContextVars that func makes will stay isolated to the 'ctx' context.<br>
<span class="gmail-"><br>
><br>
> Maybe add a short comment to explain that?<br>
<br>
</span>Added.<br></blockquote><div><br></div><div>The PEP still contains the following paragraph:</div><div><br></div><div>> Any changes to the context will be contained and persisted in the<br>> ``Context`` object on which ``run()`` is called on.<br></div><div><br></div><div>This phrase is confusing; it could be read as implying that context changes made by the function *will* get propagated back to the caller of run(), contradicting what was said earlier. Maybe it's best to just delete it? Otherwise if you intend it to add something it needs to be rephrased. Maybe "persisted" is the key word causing confusion?</div></div><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>