-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Stubs that require a version of python higher than the minimum supported by typeshed #10722
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
I think this would be a good idea. We actually already have a need for this: typeshed claims to support Python 3.7+, but the latest version of |
Oh, actually, the |
Should the field be empty by default or should it be set to typeshed's minimum supported python? |
The We should add some validation to I'm not sure what the stub uploader should do if it encounters a stubs package that doesn't have a |
Answering my own question after thinking about this a little more: I think it should add |
Makes sense. |
This is part of the work towards python/typeshed#10722 Note that the field is called `python_requires` in `setup.py`. References: - typeshed issue: python/typeshed#10722 - typeshed PR: python/typeshed#10724 - setuptools docs: https://setuptools.pypa.io/en/latest/userguide/dependency_management.html#python-requirement
Required tasks:
|
Since this issue touches that area. |
I just took a quick look on the pyright and pytype scripts. The problem here is that these tests run on the whole project. They have to become modular somehow before applying the same logic of skipping tests in mypy and stubtest. This is a bigger change than what we did with mypy. As for the specific issue you got, maybe there is a ruff rule that replaces or bans certain imports? |
This is the pytype part of python#10722
Yes, to explain the context here: as you noted, we run pytype and pyright pretty differently in CI to how to we run mypy (whether that's With our mypy tests, we do very elaborate things to try to ensure that each stubs package is only tested in isolation. That means that if stubs package When we first added the infrastructure to typeshed allowing non-types dependencies, it was decided that we'd only do this kind of thing for mypy's test scripts. For the other type checkers we run in CI, we'd take a less principled, but simpler, approach: we'd just install all our non-types dependencies together into a big soup, and then test all our stubs packages together. Since we already do the principled thing with mypy, it was thought that it probably wouldn't catch any more bugs if we also did the principled/complex thing with the other two type checkers we run in CI, so it probably wasn't worth the maintenance cost to attempt to do so. |
Yeah, that's basically just because we've got a slightly unusual situation going on right now where we've partially-but-not-completely dropped support for Python 3.7. Some, but not all of our tests, run with If you want a fix @Avasam, I'd merge a PR that did this, since we can still run our pyright tests with diff --git a/scripts/runtests.py b/scripts/runtests.py
index d7aebb9e5..b8ff184b0 100644
--- a/scripts/runtests.py
+++ b/scripts/runtests.py
@@ -96,7 +96,7 @@ def main() -> None:
strict_params = _get_strict_params(path)
print(f"\nRunning Pyright ({'stricter' if strict_params else 'base' } configs) for Python {_PYTHON_VERSION}...")
pyright_result = subprocess.run(
- [sys.executable, "tests/pyright_test.py", path, "--pythonversion", _PYTHON_VERSION] + strict_params,
+ [sys.executable, "tests/pyright_test.py", path, "--pythonversion", "3.7"] + strict_params,
stderr=subprocess.PIPE,
text=True,
) But also, January isn't too far away, so we could probably just wait until then, when the problem will fix itself as a result of us dropping support for Python 3.7 :) |
Thanks for the context. I think moving forward the whole testing process needs to be simplified, otherwise every addition will require a lot of tricky stuff and duplication of code. One way of dealing with this could be to factor out the logic that parses command line arguments to get which files need to be checked, the version checks + skipping, virtual environment creation and caching, and some other common tasks like results reporting, so that they can be used by all checks. We could maybe even go with factoring out the common bits to a state where adding a new check (new type checker!) could be made with a simple change to a subprocess call. The virtual environment creation specifically could be made its own job in CI (with proper caching even between runs) that other jobs depend on. For local tests, this can also be done perhaps with an in-project build of virtual envs that are persistent on disk until a dependency changes or some time passes since creation. This means any execution of mypy et al, pyright, pytype would create the venv once and reuse it. I don’t think I’ll have time to go through all of this in the near future but hopefully someone else does. I’ll help with this whenever I get a chance. |
Yeah. I've previously tried to somewhat consolidate our logic between our test scripts in PRs such as #8700, #9382 and #9534. It's possible there's more still that we could do. However, it's tricky to centralise logic much more IMO, because the scripts all work pretty differently (for a number of reasons, among them: the different type checkers work differently; the different scripts have different aims; and the different scripts were created by different people at different points in time rather than all together at the same time). There's also the risk that we try to abstract away the differences between the scripts too much, which can make it harder to read the code and harder to refactor the scripts. Some of the functions that I've previously added to Having said all that, though, you're very welcome to try to improve things further! :D
This is something I've been dreaming of for a while. You could maybe have a special directory for storing virtual envs for each stubs project ( But, I haven't got around to actually doing anything like that yet :) And, of course... it will only make the scripts even more complicated. Sigh. |
Note that when it comes to pyright, we don't even use a script in CI. We have typeshed/.github/workflows/tests.yml Lines 132 to 192 in 3eb9ff7
|
This makes the script usable for packages that do not support the minimum python version hardcoded in the script. Another part of python#10722
This makes the script usable for packages that do not support the minimum python version hardcoded in the script. Another part of #10722
In #10721, the seaborn stubs depend on matplotlib that only included a
py.typed
marker file in version 3.8.matplotlib version 3.8 requires python
>=3.9
which leads to the mypy tests failing on python 3.8.Alex Waygood suggests adding a
requires-python
field toMETADATA.toml
and teaching stub-uploader to include it in the generatedsetup.py
#10721 (comment).Please let us know what you think about this idea or if you have another solution.
The text was updated successfully, but these errors were encountered: