__eq__
methods disable narrowing in the else
block
#17229
Labels
__eq__
methods disable narrowing in the else
block
#17229
playground
in this case, it's safe to narrow to
Foo
in theelse
block, because theLiteral["a"]
cannot have a custom__eq__
. this means ifa == "a"
returnsFalse
, there's no chance thata
is aLiteral["a"]
, but if it returnsTrue
then it's still possible for it to be aFoo
because of theFoo.__eq__
.therefore, the narrowing should work like this:
this would also be consistent with pyright's behavior: playground
The text was updated successfully, but these errors were encountered: