Description
isinstance can accept union types as an argument, but when I use a union and another type in the isinstance call, basedpyright fails to narrow types
from typing import reveal_type, TypeAlias
class A: ...
class B: ...
class C: ...
Alias: TypeAlias = A | B
def get_foo() -> Alias | None: ...
foo: Alias | None = get_foo()
if isinstance(foo, Alias):
# this works, see https://github.com/microsoft/pyright/issues/2565
reveal_type(foo) # A | B
if isinstance(foo, (Alias, C)):
# expected A | B | C
# but got A | B | None
reveal_type(foo)
Playground
Description
isinstancecan accept union types as an argument, but when I use a union and another type in theisinstancecall, basedpyright fails to narrow typesPlayground