StandardError in Python 2 -> 3

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Nov 16 20:30:57 EST 2012


The exception hierarchy in Python 3 is shallower than in Python 2.
Here is a partial list of exceptions in Python 2:
BaseException
 +-- SystemExit
 +-- KeyboardInterrupt
 +-- GeneratorExit
 +-- Exception
 +-- StandardError
 | +-- AttributeError
 | +-- ImportError
 | +-- NameError
 | +-- TypeError
 | +-- ValueError 
 +-- Warning
and the same again in Python 3:
BaseException
 +-- SystemExit
 +-- KeyboardInterrupt
 +-- GeneratorExit
 +-- Exception
 +-- AttributeError
 +-- ImportError
 +-- NameError
 +-- SystemError
 +-- TypeError
 +-- ValueError
 +-- Warning
Note that StandardError is gone. 
Does anyone use StandardError in their own code? In Python 2, I normally 
inherit from StandardError rather than Exception. Should I stop and just 
inherit from Exception in both 2 and 3?
-- 
Steven


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /