-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
False-positive error when using Callable
in a PEP 604 type alias
#12393
Comments
I hit this with |
That is a PEP 604 type alias, and it's the same as my first example :-) If you were to write that type alias without PEP 604, it would be |
Oh duh, I misremembered what PEP 604 was. :-(
…--
--Guido (mobile)
|
The original example works correctly on master (assuming you use 3.10+). |
Not in a stub file on 3.9, I don't think? |
Hm, I just tried and first example works in a stub on 3.9, but the last example actually fails in stub on 3.9
Maybe open a separate issue to track specifically this case? |
Okay, I will open a separate issue. On mypy # test.pyi
from typing import Callable
from typing_extensions import TypeAlias
X = int | Callable[[], str | bool]
XX: TypeAlias = int | Callable[[], str | bool]
Y = int | Callable[[str | bool], str]
YY: TypeAlias = int | Callable[[str | bool], str] |
(#14158 is the follow-up issue for stubs, for those following along.) |
I tried to fix but `mypy` complains along the lines of python/mypy#12393
I tried to fix but `mypy` complains along the lines of python/mypy#12393
* MAINT: `noqa` for awkward UP007 violation I tried to fix but `mypy` complains along the lines of python/mypy#12393 * MAINT: lint: enable line-length check in `cluster` * MAINT: lint: enable line-length check in `integrate` [lint only] * MAINT: lint: enable line-length check in `interpolate` [lint only] * MAINT: lint: enable line-length check in `io` [lint only] * MAINT: lint: enable line-length check in `ndimage` [lint only] * MAINT: lint: enable line-length check in `signal` [lint only] * MAINT: lint: enable line-length check in `linalg` [lint only] * MAINT: lint: enable line-length check in `spatial` [lint only] * MAINT: lint: enable line-length check in `sparse` [lint only] * MAINT: lint: enable line-length check in `_lib` [lint only] * MAINT: lint: enable line-length check in `stats` [lint only] * MAINT: lint: enable line-length check in `special` [lint only] * MAINT: lint: enable line-length check in `optimize` [lint only] * MAINT: lint: enable line-length check in `benchmarks` [lint only] * MAINT: lint: enable line-length check in `tools` * MAINT: lint: `per-file-ignores` clean-up * MAINT: PR 19609 revisions
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
Callable
is the outermost type. The following produces no errors:There is also an additional bug that only exists for stub files running with
--python-version
set to 3.9 or lower, when using aCallable
that has a PEP 604 union as its return type or a PEP 604 union in its parameter specification, and when theCallable
is itself in a PEP 604 union:To Reproduce
.py
files..pyi
file, then run mypy on the file with--python-version=3.9
.Expected Behavior
No errors should be reported.
Cc. @JelleZijlstra
The text was updated successfully, but these errors were encountered: