I've been tripped up a couple of time by a few Exception names being lower case both in
code and tracebacks. In particular
error (all lower case)
I tend to read
error as a function instead of a class.
According to my non-scientific grep-foo, I find that ~ 300 descendant from Exceptions start with an upper case:
~/dev/cpython[master ✗] $ rg '^[ ]class [A-Z][a-zA-Z]+(' | grep Excep | wc -l
18 of those are
~/dev/cpython[master ✗] $ rg '^[ ]class Error(' | wc -l
but 4 are lower case:
~/dev/cpython[master ✗] $ rg '^[ ]*class [a-z][a-zA-Z]+(' | grep Exception Lib/sre_constants.py:class error(Exception): Lib/imaplib.py: class error(Exception): pass # Logical errors - debug required Doc/faq/design.rst: class label(Exception): pass # declare a label Lib/dbm/__init__.py:class error(Exception):
... there are probably others if they don't directly inherit from Exception of course.
My question is in two part:
1) For consistency would it make sens to try to capitalize – where possible –
Exceptions names ? For example
Error (keeping error as
an alias for backward compatibility for now).
2) If (1), would it be ok to actually give a better name to some of those exceptions ?
e.g: Lib/sre_constants.py:class error to CompileError for example.