-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Type-check on all Python versions #4352
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[mypy] | ||
# CI should test for all versions, local development gets hints for oldest supported | ||
# Some upstream typeshed distutils stubs fixes are necessary before we can start testing on Python 3.12 | ||
python_version = 3.8 | ||
# But our testing setup doesn't allow passing CLI arguments, so local devs have to set this manually. | ||
# python_version = 3.8 | ||
strict = False | ||
warn_unused_ignores = True | ||
warn_redundant_casts = True | ||
|
@@ -30,15 +30,19 @@ disable_error_code = attr-defined | |
[mypy-pkg_resources.tests.*] | ||
disable_error_code = import-not-found | ||
|
||
# - distutils._modified has different errors on Python 3.8 [import-untyped], on Python 3.9+ [import-not-found] | ||
# - distutils doesn't exist on Python 3.12, unfortunately, this means typing | ||
# will be missing for subclasses of distutils on Python 3.12 until either: | ||
# - support for `SETUPTOOLS_USE_DISTUTILS=stdlib` is dropped (#3625) | ||
# for setuptools to import `_distutils` directly | ||
# - or non-stdlib distutils typings are exposed | ||
Comment on lines
+35
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This includes potentially moving Or typeshed accepting to publish a non-stdlib Until then, Python 3.12+ users won't be able to have complete typing without Anyway, not a huge concern just yet, but something to start thinking about. |
||
# - All jaraco modules are still untyped | ||
# - _validate_project sometimes complains about trove_classifiers (#4296) | ||
# - wheel appears to be untyped | ||
[mypy-distutils._modified,jaraco.*,trove_classifiers,wheel.*] | ||
[mypy-distutils.*,jaraco.*,trove_classifiers,wheel.*] | ||
ignore_missing_imports = True | ||
|
||
# Even when excluding a module, import issues can show up due to following import | ||
# https://github.com/python/mypy/issues/11936#issuecomment-1466764006 | ||
[mypy-setuptools.config._validate_pyproject.*] | ||
[mypy-setuptools.config._validate_pyproject.*,setuptools._distutils.*] | ||
follow_imports = silent | ||
# silent => ignore errors when following imports |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,9 @@ | ||||||||||
"""Extensions to the 'distutils' for large or complex distributions""" | ||||||||||
# mypy: disable_error_code=override | ||||||||||
# Command.reinitialize_command has an extra **kw param that distutils doesn't have | ||||||||||
# Can't disable on the exact line because distutils doesn't exists on Python 3.12 | ||||||||||
# and mypy isn't aware of distutils_hack, causing distutils.core.Command to be Any, | ||||||||||
# and a [unused-ignore] to be raised on 3.12+ | ||||||||||
Comment on lines
+4
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively:
Suggested change
|
||||||||||
|
||||||||||
from __future__ import annotations | ||||||||||
|
||||||||||
|
@@ -114,8 +119,10 @@ def setup(**attrs): | |||||||||
setup.__doc__ = distutils.core.setup.__doc__ | ||||||||||
|
||||||||||
if TYPE_CHECKING: | ||||||||||
from typing_extensions import TypeAlias | ||||||||||
|
||||||||||
# Work around a mypy issue where type[T] can't be used as a base: https://github.com/python/mypy/issues/10962 | ||||||||||
_Command = distutils.core.Command | ||||||||||
_Command: TypeAlias = distutils.core.Command | ||||||||||
else: | ||||||||||
_Command = monkey.get_unpatched(distutils.core.Command) | ||||||||||
|
||||||||||
|
@@ -207,7 +214,7 @@ def ensure_string_list(self, option): | |||||||||
"'%s' must be a list of strings (got %r)" % (option, val) | ||||||||||
) | ||||||||||
|
||||||||||
@overload # type:ignore[override] # Extra **kw param | ||||||||||
@overload | ||||||||||
def reinitialize_command( | ||||||||||
self, command: str, reinit_subcommands: bool = False, **kw | ||||||||||
) -> _Command: ... | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,11 @@ | |
Generic, | ||
Iterable, | ||
Iterator, | ||
List, | ||
Tuple, | ||
TypeVar, | ||
Union, | ||
cast, | ||
) | ||
|
||
from packaging.markers import default_environment as marker_env | ||
|
@@ -108,7 +110,8 @@ def _apply( | |
filenames = [*other_files, filepath] | ||
|
||
try: | ||
_Distribution.parse_config_files(dist, filenames=filenames) # type: ignore[arg-type] # TODO: fix in distutils stubs | ||
# TODO: Temporary cast until mypy 1.12 is released with upstream fixes from typeshed | ||
_Distribution.parse_config_files(dist, filenames=cast(List[str], filenames)) | ||
Comment on lines
+113
to
+114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
handlers = parse_configuration( | ||
dist, dist.command_options, ignore_option_errors=ignore_option_errors | ||
) | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -195,8 +195,10 @@ def check_packages(dist, attr, value): | |||||
|
||||||
|
||||||
if TYPE_CHECKING: | ||||||
from typing_extensions import TypeAlias | ||||||
|
||||||
# Work around a mypy issue where type[T] can't be used as a base: https://github.com/python/mypy/issues/10962 | ||||||
_Distribution = distutils.core.Distribution | ||||||
_Distribution: TypeAlias = distutils.core.Distribution | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this one we can do:
Suggested change
and remove the import for ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you already approved and these are changed in #4504 , I'll keep it as-is for this PR |
||||||
else: | ||||||
_Distribution = get_unpatched(distutils.core.Distribution) | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -27,8 +27,10 @@ def _have_cython(): | |||||
# for compatibility | ||||||
have_pyrex = _have_cython | ||||||
if TYPE_CHECKING: | ||||||
from typing_extensions import TypeAlias | ||||||
|
||||||
# Work around a mypy issue where type[T] can't be used as a base: https://github.com/python/mypy/issues/10962 | ||||||
_Extension = distutils.core.Extension | ||||||
_Extension: TypeAlias = distutils.core.Extension | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
And then we can drop the |
||||||
else: | ||||||
_Extension = get_unpatched(distutils.core.Extension) | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would love if there was a way to tell the CI to pass the
--python-version
argument to override this config so that IDEs and maybe default local runs can test against the oldest supported Python version.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pytest-mypy
mentions the following:Not sure if that is useful to achieve what you want via
conftest.py
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would, something like:
Since you approved, mind if I tackle your comments in a follow-up ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
Is that going to behave differently than just omitting
python_version
inmypy.ini
?pytest-mypy
would force the contributor to check on the current version anyway, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I never run pytest-mypy locally. But yes that would mean that the mypy-test commands would always check for the executed Python. A more complete snippet of code would probably check if this is being run on the CI (check for GitHub env var) and whether the dev already passed
--python-version
as to not overwrite it (let's say they runpytest-mypy
directly w/o tox)