-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
False-positive error when using Callable in a PEP 604 type alias #12393
Copy link
Copy link
Closed
Labels
affects-typeshedAnything that blocks a typeshed changeAnything that blocks a typeshed changebugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codetopic-pep-604PEP 604 (union | operator)PEP 604 (union | operator)topic-type-aliasTypeAlias and other type alias issuesTypeAlias and other type alias issues
Metadata
Metadata
Assignees
Labels
affects-typeshedAnything that blocks a typeshed changeAnything that blocks a typeshed changebugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codetopic-pep-604PEP 604 (union | operator)PEP 604 (union | operator)topic-type-aliasTypeAlias and other type alias issuesTypeAlias and other type alias issues
Bug Report
The following snippet works fine at runtime on 3.10+. It should be accepted as a valid type alias definition on Python 3.10+ (and should be accepted in stub files regardless of Python version). However, mypy raises a false-positive error. The error does not go away if you use
typing.TypeAlias:Mypy does accept the following (with the order of types reversed) as a valid type alias on Python 3.10+ and in stub files:
Much like with #12392, this error is only reproduceable if
Callableis the outermost type. The following produces no errors:There is also an additional bug that only exists for stub files running with
--python-versionset to 3.9 or lower, when using aCallablethat has a PEP 604 union as its return type or a PEP 604 union in its parameter specification, and when theCallableis itself in a PEP 604 union:To Reproduce
.pyfiles..pyifile, then run mypy on the file with--python-version=3.9.Expected Behavior
No errors should be reported.
Cc. @JelleZijlstra