[Python-ideas] Fwd: Null coalescing operator
Chris Angelico
rosuav at gmail.com
Mon Sep 12 10:09:09 EDT 2016
On Tue, Sep 13, 2016 at 12:03 AM, Rob Cliffe <rob.cliffe at btinternet.com> wrote:
> Assuming you can't break existing code that already traps TypeError,
> AttributeError, etc., I don't see how you can do this without
> having separated kinds of NoneError which were subclasses of TypeError,
> AttributeError, etc.
class NoneError(Exception): pass
class TypeNoneError(TypeError, NoneError): pass
class AttributeNoneError(AttributeError, NoneError): pass
Now you can catch NoneError to catch None.xyz, or AttributeError to
catch foo.xyz for any foo.
I don't think it's good, but it's possible.
ChrisA
More information about the Python-ideas
mailing list