The type guard isinstance(x, object) should be a no-op because all objects in Python derive from object, but pyright's narrowing logic (in the positive direction) is not treating it as a no-op.
import dataclasses
from typing import reveal_type
def func(x: object) -> None:
if dataclasses.is_dataclass(x) and isinstance(x, object):
reveal_type(x)
print(dataclasses.asdict(x))
The type guard
isinstance(x, object)
should be a no-op because all objects in Python derive fromobject
, but pyright's narrowing logic (in the positive direction) is not treating it as a no-op.This comes from this discussion in typeshed.