Skip to content

isinstance narrowing incorrect for object filter #8520

@erictraut

Description

@erictraut

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))

This comes from this discussion in typeshed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions