[Python-ideas] Fwd: Null coalescing operator

Random832 random832 at fastmail.com
Mon Sep 12 09:13:06 EDT 2016


On Mon, Sep 12, 2016, at 06:01, Ivan Levkivskyi wrote:
>  I like this idea, I would propose a (maybe crazy) addition to it. What
> about a special exception NoneError, that will catch TypeError,
> AttributeError etc. but only when it was caused by None(),
> None.attr, None[1], etc. With this one can write:
> 
> x = a.b()[0] except NoneError: 'default'
> 
> without a risk of catching other (unrelated) exceptions.

Unless there's another None somewhere inside b or b().__getitem__.


More information about the Python-ideas mailing list