Open KotlinIsland opened 4 months ago
the issue is actually that it only narrows literals:
def f(a: int | None, b: int):
if a == 1:
reveal_type(a) # Literal[1]
if a == b:
reveal_type(a) # int | None
upstream issue: https://github.com/microsoft/pyright/issues/8065
actually this would be unsafe because a subtype of int
could define a custom __eq__
. so this should only work if the class is @final
narrowing with is
instead of ==
should also work because it doesn't use __eq__