(original) (raw)
On Thu, Jan 4, 2018 at 4:56 PM, Greg Ewing <greg.ewing@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.)