KEMBAR78
`isinstance` can take `typing.Union` as second arg in 3.10 and newer · Issue #12137 · python/typeshed · GitHub
Skip to content

isinstance can take typing.Union as second arg in 3.10 and newer #12137

@hauntsaninja

Description

@hauntsaninja

Currently it allows for types.UnionType but not typing.Union

if sys.version_info >= (3, 10):
    _ClassInfo: TypeAlias = type | types.UnionType | tuple[_ClassInfo, ...]
else:
    _ClassInfo: TypeAlias = type | tuple[_ClassInfo, ...]

def isinstance(obj: object, class_or_tuple: _ClassInfo, /) -> bool: ...

I think mypy currently assumes that whatever typeshed says for isinstance has no false positives

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions