```python n = 0 class Test: def __bool__(self): global n n += 1 return False Test() and False or False assert n == 1 ``` CPython optimizes this check in: https://github.com/python/cpython/blob/54ab9ad312ea53db40e31712454272e1d4c0315f/Python/compile.c#L8708-L8721
Activity
crazymerlyn commentedon Sep 7, 2024
Looks like the assertion fails again since python 3.12: https://godbolt.org/z/qoKcdvz4T
moreal commentedon Feb 14, 2026
In CPython 3.14, the assertion has started to pass again.
https://godbolt.org/z/1Genzf9sE
Add runtime test for redundant __bool__ check (issue RustPython#3567)
Add runtime test for redundant __bool__ check (issue RustPython#3567)
Optimize redundant bool check (#7176)
Optimize redundant bool check (RustPython#7176)
Optimize redundant bool check (#7176)