-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
try from typing import ParamSpec except from typing_ext import ParamSpec
not working
#16903
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
Comments
This way of conditional import is not currently supported by mypy. You'll have to use a version check to do the import. import sys
from typing import Callable
if sys.version_info >= (3, 10):
from typing import ParamSpec
else:
from typing_extensions import ParamSpec
P = ParamSpec("P")
def func(arg: Callable[P, None]) -> None:
return None You can read more about it here |
Duplicate of #14220 |
Hmm... it doesn't works very well. from sys import version_info
if version_info >= (3, 10):
from typing import ParamSpec
else:
from typing_extensions import ParamSpec Mypy says |
Correct. You need to do this: import sys
if sys.version_info >= (3, 10):
from typing import ParamSpec
else:
from typing_extensions import ParamSpec You can't do |
Bug Report
try-except imported ParamSpec is unusable.
This makes
ParamSpec("P")
become an invaild type.To Reproduce
Expected Behavior
No error
Actual Behavior
error: The first argument to Callable must be a list of types, parameter specification, or "..." [valid-type]
Your Environment
Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-94-generic x86_64)
1.8.0 (compiled: yes)
mypy.ini
(and other config files): None3.8.18
Reproduce repository
The text was updated successfully, but these errors were encountered: