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
Use of ParamSpec
introduced in #3396 only works in Python 3.10+
#3397
Comments
Thanks for the report! We also have an inadequate-tests problem then... |
We do have a (recent) precedent for parameterizing type-checker tests over python versions 😄 Tests that I can think of:
I was trying to remember: what is the reason why we avoid adding |
Ensuring that we don't pick up an accidental hard-dependency; it is in our tools and coverage deps, just not the minimal test deps, and I think that's the right balance. |
In my opinion, depending on It will simplify a lot of things for us. |
The main argument against is that minimising dependencies is a big deal for PyPy, CPython, and other foundational projects. Maybe it's worth it anyway; I'd need to look into the compatibility story with prerelease and nightly builds. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Quick untested hack: 854e8ab |
Your hack should work. Type checkers are special cased to always know what |
Ooh, thanks for dropping by! I'm a little concerned that the hack will fail in some environments, so what about: if typing.TYPE_CHECKING or sys.version_info[:2] >= (3, 10):
from typing import Concatenate, ParamSpec
else:
try:
from typing_extensions import Concatenate, ParamSpec
except ImportError: # pragma: no cover
ParamSpec = None |
No, type checkers will complain about that when checking targeting Python 3.9. See https://mypy-play.net/?mypy=latest&python=3.9&gist=0495f5e1337cd862c26dbb2de4d05633 I would do:
I guess if you don't fully believe that all type checkers always know about typing_extensions, you could hedge a little more with:
But they really always do. typing_extensions has been in the standard library since Python 2.7, don't you know :-) https://github.com/python/typeshed/blob/2c052651e953109c94ae998f5ccc6d043df060c9/stdlib/VERSIONS#L273 |
Option 1 does indeed work with pyright without
In the case of mypy, $ mypy scratch/scratch.py --python-version=3.9
Traceback (most recent call last):
File "C:\Users\rsokl\miniconda3\envs\hydra-zen\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\rsokl\miniconda3\envs\hydra-zen\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\rsokl\miniconda3\envs\hydra-zen\Scripts\mypy.exe\__main__.py", line 4, in <module>
File "C:\Users\rsokl\miniconda3\envs\hydra-zen\lib\site-packages\mypy\__main__.py", line 6, in <module>
from mypy.main import main, process_options
File "mypy\main.py", line 11, in <module>
ModuleNotFoundError: No module named 'typing_extensions' |
@rsokl that traceback is mypy itself crashing. The better proof for this is using the
Or more thoroughly, see that numpy stops being found, but typing_extensions is still found:
|
Ah, gotchya. Thanks for clarifying @hauntsaninja . I should have couched my post with "I am sure that you know what you are talking about, whereas I have little experience with mypy" 😅 |
The pattern used by #3396 to leverage
ParamSpec
hypothesis/hypothesis-python/src/hypothesis/strategies/_internal/core.py
Lines 123 to 129 in 0738717
does not actually work with the
typing_extensions
backport:pyright repro
It seems like nested try-excepts are not supported by mypy:
The following works for mypy for both Python 3.10 and the typing-extensions backport, but only works for pyright for Python 3.10 (potentially relevant comment from Eric Traut):
Whereas this works for pyright under all circumstances, but fails in mypy when typing-extensions is not installed:
I've gotta go to bed.. @sobolevn I'm wondering if you have any recommendations here.
The text was updated successfully, but these errors were encountered: