On 9 January 2018 at 05:34, Yury Selivanov <yselivanov...@gmail.com> wrote: > Maybe we can rename ContextVar.get() to ContextVar.lookup()? This > would help to avoid potential confusion between Context.get() and > ContextVar.get().
I think this would also tie in nicely with the PEP 568 draft, where "ContextVar.lookup()" may end up scanning a chain of Context mappings before falling back on the given default value. That said, I do wonder if this may be a case where a dual API might be appropriate (ala dict.__getitem__ vs dict.get), such that you have: ContextVar.get(default=None) -> Optional[T] # Missing -> None ContextVar.lookup() -> T # Missing -> raise LookupError If you set a default on the ContextVar itself, they'd always be identical (since you'll never hit the "Missing" case), but they'd mimic the dict.__getitem__ vs dict.get split if no var level default was specified. The conservative option would be to start with only the `ContextVar.lookup` method, and then add `ContextVar.get` later if it's absence proved sufficiently irritating. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com