Pyright does not currently perform proper subtyping checks for TypeIs and TypeGuard. In particular, it treats TypeIs[x] as equivalent to bool when performing subtyping checks. TypeIs[x] should be considered a subtype of bool, and TypeIs[x] should be considered a subtype of TypeIs[y] only if x is a subtype of y.
This can be demonstrated in this code, where the Any input to is_dataclass should cause the overload logic to resolve both overloads rather than the first.
import dataclasses
from typing import reveal_type
def func(x: Any) -> None:
if dataclasses.is_dataclass(x) and isinstance(x, object):
reveal_type(x)
print(dataclasses.asdict(x))
This is related to this discussion.
Pyright does not currently perform proper subtyping checks for
TypeIsandTypeGuard. In particular, it treatsTypeIs[x]as equivalent toboolwhen performing subtyping checks.TypeIs[x]should be considered a subtype ofbool, andTypeIs[x]should be considered a subtype ofTypeIs[y]only ifxis a subtype ofy.This can be demonstrated in this code, where the
Anyinput tois_dataclassshould cause the overload logic to resolve both overloads rather than the first.This is related to this discussion.