[Python-Dev] PEP 567 v2 (original) (raw)

Guido van Rossum guido at python.org
Thu Jan 4 10:56:23 EST 2018


On Thu, Jan 4, 2018 at 3:25 AM, Paul Moore <p.f.moore at gmail.com> wrote:

On 4 January 2018 at 00:17, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote: > Guido van Rossum wrote: >> >> contextvars.copycontext().run(func, ) > > If contexts are immutable, why is there something > called copycontext?

Agreed. This was something that bothered me, too. I mentioned it in my review, but that seemed to get lost in the other comments in this thread... I get the impression that the logic is that the context is immutable, but the ContextVars that it contains aren't, and the copy is deep (at least 1 level deep) so you copy then change the value of a ContextVar. But rereading that sentence, it sounds confused even to me, so it's either not right or the implementation falls foul of "If the implementation is hard to explain, it's a bad idea." :-)

It was get_context() in an earlier version of PEP 567. We changed it to copy_context() believing that that would clarify that you get a clone that is unaffected by subsequent ContextVar.set() operations (which affect the current context rather than the copy you just got).

[The discussion is fragmentary because Yury is on vacation until the 15th and I am scrambling for time myself. But your long post is saved, and not forgotten.]

-- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180104/5e9febb3/attachment.html>



More information about the Python-Dev mailing list