Description
Documentation
In https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement,
The existing documentation states, "The current code generator emits no code for an assert statement when optimization is requested at compile time." This could include more details that setting the -O
flag on the Python executable, or setting the PYTHONOPTIMIZE
environment variable, will disable all asserts
statements in code. Another improvement is a reminder, especially for library code authors, that if their code logic depends on assert
statements as part of their critical code logic, that logic could break when optimization is enabled from the command line or in the environment. Another risk is evaluating function variables with assert
in order to avoid typing errors on the return value, like declaring the return type as -> int
, and adding an assert x is not None
before a return x
statement.