- object
- BaseException
- Exception
- ArithmeticError
- FloatingPointError
- OverflowError
- ZeroDivisionError
- AssertionError
- AttributeError
- BufferError
- EOFError
- ImportError
- ModuleNotFoundError
- LookupError
- IndexError
- KeyError
- MemoryError
- NameError
- UnboundLocalError
- OSError aka EnvironmentError aka IOError
- BlockingIOError
- ChildProcessError
- ConnectionError
- BrokenPipeError
- ConnectionAbortedError
- ConnectionRefusedError
- ConnectionResetError
- FileExistsError
- FileNotFoundError
- InterruptedError
- IsADirectoryError
- NotADirectoryError
- PermissionError
- ProcessLookupError
- TimeoutError
- ReferenceError
- RuntimeError
- NotImplementedError
- RecursionError
- StopAsyncIteration
- StopIteration
- SyntaxError
- IndentationError
- TabError
- IndentationError
- SystemError
- TypeError
- ValueError
- UnicodeError
- UnicodeDecodeError
- UnicodeEncodeError
- UnicodeTranslateError
- UnicodeError
- Warning
- BytesWarning
- DeprecationWarning
- FutureWarning
- ImportWarning
- PendingDeprecationWarning
- ResourceWarning
- RuntimeWarning
- SyntaxWarning
- UnicodeWarning
- UserWarning
- ArithmeticError
- GeneratorExit
- KeyboardInterrupt
- SystemExit
- Exception
- BaseException
Last active
May 26, 2021 19:36
-
-
Save ajschumacher/560d703ca9d0f3bf48a06562d62a7f02 to your computer and use it in GitHub Desktop.
Python 3.7.4 exception hierarchy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# inspired by and based on: | |
# https://julien.danjou.info/python-exceptions-guide/ | |
# https://github.com/jd/julien.danjou.info/blob/master/bin/generate-python-exceptions-graph.py | |
import builtins | |
edges = set() | |
synonyms = {} | |
for name in dir(builtins): | |
item = getattr(builtins, name) | |
if isinstance(item, type) and BaseException in item.__mro__: | |
assert len(item.__bases__) == 1 | |
edges.add((item.__bases__[0].__name__, item.__name__)) | |
if item.__name__ != name: | |
synonyms.setdefault(item.__name__, []).append(name) | |
edges = sorted(edges) | |
def show(name, level=0, maxlevel=999): | |
if level > maxlevel: | |
return | |
extra = '' | |
if name in synonyms: | |
extra = ' aka ' + ' aka '.join(sorted(synonyms[name])) | |
print(' ' * level + ' * ' + name + extra) | |
for child in [child for parent, child in edges if parent == name]: | |
show(child, level + 1, maxlevel=maxlevel) | |
show('object') | |
show('Exception', maxlevel=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment