Closed
Description
Description
We have an existing code path in Type::bool
that tries to prevent infinite recursion:
ruff/crates/red_knot_python_semantic/src/types.rs
Lines 1777 to 1786 in 13e7afc
and a test for it here:
ruff/crates/red_knot_python_semantic/resources/mdtest/unary/not.md
Lines 140 to 145 in 13e7afc
But this only checks the case where __bool__
has the exact type Literal[bool]
. It fails if the type is a union that contains Literal[bool]
, for example:
def flag() -> bool: return True
class Boom:
if flag():
__bool__ = bool
else:
__bool__ = int
bool(Boom())
> cargo run --bin red_knot -- --project /path/to/folder/with/example
thread '<unknown>' has overflowed its stack
fatal runtime error: stack overflow