-
Notifications
You must be signed in to change notification settings - Fork 276
Closed
Description
Describe the Bug
I came across something during my own work on pytype2 and thought I'd check whether pyrefly has the same problem. Turns out it does:
def f(cls: type[int], x: int | str) -> None:
if isinstance(x, cls):
reveal_type(x) # reveals int - ok
else:
reveal_type(x) # reveals str - too narrowThe first revealed type is fine but the second revealed type is too narrow. Someone could call f(bool, 42) and would end up in the else branch thinking that 42 is a str.
I think you simply cannot narrow the negative case for isinstance if its second argument is of type type[T] but not the literal name of a class.
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels