A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-January/151611.html below:

[Python-Dev] PEP 567 v2

[Python-Dev] PEP 567 v2 [Python-Dev] PEP 567 v2Victor Stinner victor.stinner at gmail.com
Fri Jan 5 05:05:18 EST 2018
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>
More information about the Python-Dev mailing list

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