-
Notifications
You must be signed in to change notification settings - Fork 159
Open
Labels
Description
Describe the Bug
Actual:
from typing import reveal_type
def test[T: int | str](value: T) -> T:
if isinstance(value, int):
reveal_type(value) # revealed type: int
return value # This errors
else:
reveal_type(value)
return value # This is ok
Python: 3.13
Type narrowing for typeVars seems to be wrong.
After narrowing a variable that has a typeVar as its type, Pyrefly seems to forget that it is a typeVar so, it is not compatible with the original type anymore, even though the value didn't change.
In the example above I would expect Pyrefly to narrow the type of value
to T & int
or to also narrow T
to int
.