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

Victor Stinner victor.stinner at gmail.com
Wed Jan 3 05:04:46 EST 2018


Le 3 janv. 2018 06:38, "Guido van Rossum" <guido at python.org> a écrit :

But is there a common use case? For var.get() I'd rather just pass the default or catch the exception if the flow is different. Using ctx[var] is rare (mostly for printing contexts, and perhaps for explaining var.get()).

I don't think that it would be a common use case. Maybe we don't need is_set(), I'm fine with catching an exception.

But for introspection at least, it would help to expose the default as a read-only attribute, no?

Another example of a mapping with default value:

https://docs.python.org/dev/library/collections.html#collections.defaultdict

And defaultdict has a default_factory attribute. The difference here is that default_factory is mandatory. ContextVar would be simpler if the default would be mandatory as well :-)

Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180103/b84df975/attachment.html>



More information about the Python-Dev mailing list