Skip to content

(🎁) isinstance/issubclass only accept typing.Unions of types, not other type forms #12370

Open
@KotlinIsland

Description

@KotlinIsland

Until type forms are properly supported by the type system, I wonder if this could be special cased?

from typing import Any

isinstance(1, str | Any)  # no error, fails at runtime with TypeError: typing.Any cannot be used with issubclass()

FYI mypy is incorrectly inferring this as a types.UnionType but it is actually a typing.Union(#12369), I don't think you can have a UnionType with type forms in it.

PyCharm correctly warns here:
image

related: python/typeshed/issues/7505

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions