[Python-Dev] PEP 567 v2

Guido van Rossum guido at python.org
Wed Jan 3 00:42:17 EST 2018


On Tue, Jan 2, 2018 at 4:51 PM, Victor Stinner <victor.stinner at gmail.com>
wrote:

> Why ContextVar.reset(token) does nothing at the second call with the same
> token? What is the purpose of Token._used? I guess that there is an use
> case to justify this behaviour.
>
> reset() should have a result: true if the variable was restored to its
> previous state, false if reset() did nothing because the token was already
> used. And/Or Token should have a read-only "used" property.
>

That depends again on the use case. The only real purpose for reset() is to
be able to write a context manager that sets and restores a context
variable (like in `with decimal.localcontext()`). Handling double resets is
about as useful as specifying what happens if __exit__ is called twice.

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


More information about the Python-Dev mailing list