Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KotlinIsland opened this issue Mar 17, 2022 · 0 comments
Labels
feature topic-pep-604 PEP 604 (union | operator)

Comments

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Mar 17, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-pep-604 PEP 604 (union | operator)
Projects
None yet
Development

No branches or pull requests

2 participants