To check for “shouldn't happen” errors, you can use
an assert statement:
asserte1asserte1,e2
where
is
some condition that should be true. If the condition
fails, an e1AssertionError exception
is raised (see exceptions below). If a
second expression
is
provided, the value of that expression is passed with
the exception.e2
Assertion checking can be disabled by running Python
with the -O (optimize) option.