Message414837
The Python reference says:
(1) https://docs.python.org/3/library/exceptions.html#concrete-exceptions
exception AssertionError
Raised when an assert statement fails.
(2) https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement
"assert ..." is equivalent to "if __debug__: ..."
From this, one can infer the guarantee "the -O flag will suppress AssertionError exceptions from being raised".
However, there is code in the Python standard library that does a direct "raise AssertionError" (strictly speaking, in violation of (1)), and it is just reasonable to assume that other code following the design of that would then also want to do a direct "raise AssertionError".
This happens e.g. in many methods defined in: unittest/mock.py
The most appropriate fix here may be to change the documentation to not say:
===
exception AssertionError
Raised when an assert statement fails.
===
but instead:
===
exception AssertionError
An assert[{add reference to `assert` definition}] statement fails, or a unit testing related assert{...}() callable detects an assertion violation.
=== |
|
Date |
User |
Action |
Args |
2022-03-10 09:44:46 | tfish2 | set | recipients:
+ tfish2 |
2022-03-10 09:44:46 | tfish2 | set | messageid: <1646905486.67.0.783441302019.issue46972@roundup.psfhosted.org> |
2022-03-10 09:44:46 | tfish2 | link | issue46972 messages |
2022-03-10 09:44:46 | tfish2 | create | |
|