-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed as not planned
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-604PEP 604 (union | operator)PEP 604 (union | operator)topic-type-aliasTypeAlias and other type alias issuesTypeAlias and other type alias issues
Description
Bug Report
I'm getting errors when using an alias of a union type as the second argument to isinstance
To Reproduce
IntOrStr = int | str
foo = 0
bar = ""
if isinstance(foo, IntOrStr):
print("foo is an IntOrStr")
if isinstance(bar, int | str):
print("bar is an IntOrStr")
Expected Behavior
mypy shouldn't output any errors
Actual Behavior
mypy_isinstance_with_union_alias_issue.py:6: error: Parameterized generics cannot be used with class or instance checks [misc]
mypy_isinstance_with_union_alias_issue.py:6: error: Argument 2 to "isinstance" has incompatible type "object"; expected "Union[type, UnionType, Tuple[Union[type, UnionType, Tuple[Any, ...]], ...]]" [arg-type]
Your Environment
- Mypy version used: 0.991
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini
(and other config files): none - Python version used: 3.11.0
Thanks!
intgr and jgillard
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-604PEP 604 (union | operator)PEP 604 (union | operator)topic-type-aliasTypeAlias and other type alias issuesTypeAlias and other type alias issues