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 is false, Python raises an e1AssertionError exception (see Section 25, “Exceptions: Error signaling and handling”).
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.