basedpyright
basedpyright copied to clipboard
narrowing should work on values that are arent literals if their type is `@final`
def f(a: int | None, b: int):
if a == b:
reveal_type(a) # int | None
if b == a:
reveal_type(a) # int | None
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__