Re: [Python-Dev] PEP 567 v2
Victor:
ContextVar would be simpler if the default would be mandatory as well :-)
If we modify ContextVar to use None as the default value, the 'default' parameter of ContextVar.get() becomes useless, ContextVar.get() and context[var] behaviour becomes obvious. Token.MISSING could also be removed. Since it's not possible to delete a variable, would it be crazy to always initialize variables with a value, None by default? Decimal context is given as an example of contextvars user. Decimal already has a default context. I don't know numpy.errstate: would it make sense to initialize it to None? If someone really needs the crazy case of "uninitialized" variable, a custom "UNINITIALIZED = object()" can be used, no? With these proposed changes, there is no more need to worry if a variable is set or not. It's unclear to me if context.items() contains variables which weren't explicit set, and so are set to their default value. Same question for "var in context" test. If variables always have a value, I would expect that "var in context" is always true but I don't understand if it's technically possible to implement it or even if it makes sense :-) Maybe my whole proposed change doesn't make sense? Victor
participants (1)
-
Victor Stinner