[Python-Dev] PEP 567 v2

Guido van Rossum guido at python.org
Thu Jan 4 19:52:09 EST 2018


On Thu, Jan 4, 2018 at 4:56 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>
wrote:

> Guido van Rossum wrote:
>
>> 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).
>>
>
> In that case it seems clear to me that "the context" is
> conceptually a mutable mapping. The fact that it happens
> to be built out of immutable components is an implementation
> detail that user-level docs should not be talking about.
>

Well, it's not *immutable* (it shouldn't support hash()), but it doesn't
follow the MutableMapping protocol -- it only follows the Mapping protocol.
Note that the latter carefully doesn't call itself ImmutableMapping.
Context is a mutable object that implements the Mapping protocol. The only
way to mutate a Context is to use var.set() when that Context is the
current context. (Modulo the caching bug discussed in the subthread with
Nathaniel.)

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


More information about the Python-Dev mailing list