Currently, Context.get(var) returns None when "var in context" is false. That's surprising and different than var.get(), especially when var has a default value. Code: --- import contextvars name = contextvars.ContextVar('name', default='victor') context = contextvars.copy_context() print(name in context) print(context.get(name)) print(name.get()) --- Output: --- False None victor --- Context.get() must raise a lookup error by default if var is not in context. It should return the default argument if it's set, it's just that the default parameter must not have a default value (None). I'l fine that Context.get(default=None) and var.get() behaves differently (return None vs victor in my example) when var isn't set and var has a default value. Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180105/0ae99702/attachment.html>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4