[Python-ideas] Null coalescing operator

Paul Moore p.f.moore at gmail.com
Sat Sep 10 13:44:46 EDT 2016


On 10 September 2016 at 18:26, Guido van Rossum <guido at python.org> wrote:
> IMO the key syntax is
> simply one for accessing attributes returning None instead of raising
> AttributeError, so that e.g. `foo?.bar?.baz` is roughly equivalent to
> `foo.bar.baz if (foo is not None and foo.bar is not None) else None`,
> except evaluating foo and foo.bar only once.

If we're not looking to use all the other null-coalescing variants
(?=, ?(), ...) - which is something I'm pleased about, as I do think
that scattering that many ?'s about is likely to lead to ugly code -
then it would probably be fine to just use ? for this operation, so
we'd have foo?bar?baz rather than needing foo?.bar?.baz.

Paul


More information about the Python-ideas mailing list