From 2ee6ac99a3b617b1a6f3a894299862502f45e2fd Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 5 Mar 2024 10:58:22 -0500 Subject: [PATCH] Turn on mypy type-checking in CI --- mypy.ini | 37 +++++++------------ pyproject.toml | 3 -- setup.cfg | 7 ++-- setuptools/command/build_ext.py | 2 +- setuptools/command/editable_wheel.py | 2 +- .../fastjsonschema_validations.py | 1 - 6 files changed, 20 insertions(+), 32 deletions(-) diff --git a/mypy.ini b/mypy.ini index e0fa8e5c476..42ade6537ee 100644 --- a/mypy.ini +++ b/mypy.ini @@ -13,30 +13,21 @@ exclude = (?x)( | ^setuptools/_distutils/ # Vendored | ^setuptools/config/_validate_pyproject/ # Auto-generated ) -disable_error_code = - # TODO: Test environment is not yet properly configured to install all imported packages - # import-not-found, # This can be left commented out for local runs until we enforce running mypy in the CI - # TODO: Not all dependencies are typed. Namely: distutils._modified, wheel.wheelfile, and jaraco.* - import-untyped, - # Ignoring attr-defined because setuptools wraps a lot of distutils classes, adding new attributes, - # w/o updating all the attributes and return types from the base classes for type-checkers to understand - # Especially with setuptools.dist.command vs distutils.dist.command vs setuptools._distutils.dist.command - # *.extern modules that actually live in *._vendor will also cause attr-defined issues on import - attr-defined, +# Ignoring attr-defined because setuptools wraps a lot of distutils classes, adding new attributes, +# w/o updating all the attributes and return types from the base classes for type-checkers to understand +# Especially with setuptools.dist.command vs distutils.dist.command vs setuptools._distutils.dist.command +# *.extern modules that actually live in *._vendor will also cause attr-defined issues on import +disable_error_code = attr-defined -# Avoid raising issues when importing from "extern" modules, as those are added to path dynamically. -# https://github.com/pypa/setuptools/pull/3979#discussion_r1367968993 -[mypy-pkg_resources.extern.*,setuptools.extern.*] +# - Avoid raising issues when importing from "extern" modules, as those are added to path dynamically. +# https://github.com/pypa/setuptools/pull/3979#discussion_r1367968993 +# - distutils._modified has different errors on Python 3.8 [import-untyped], on Python 3.9+ [import-not-found] +# - All jaraco modules are still untyped +[mypy-pkg_resources.extern.*,setuptools.extern.*,distutils._modified,jaraco.*] ignore_missing_imports = True -[mypy-pkg_resources.tests.*,setuptools.tests.*] -disable_error_code = - # Tests include creating dynamic modules that won't exists statically before the test is run. - # Let's ignore all "import-not-found", as if an import really wasn't found, then the test would fail. - import-not-found, - # mmany untyped "jaraco" modules - import-untyped, - -# Mypy issue, this vendored module is already excluded! -[mypy-setuptools._vendor.packaging._manylinux] +# - pkg_resources tests create modules that won't exists statically before the test is run. +# Let's ignore all "import-not-found" since, if an import really wasn't found, then the test would fail. +# - setuptools._vendor.packaging._manylinux: Mypy issue, this vendored module is already excluded! +[mypy-pkg_resources.tests.*,setuptools._vendor.packaging._manylinux] disable_error_code = import-not-found diff --git a/pyproject.toml b/pyproject.toml index cd95aad07f8..58aacd9fe39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,3 @@ build-backend = "setuptools.build_meta" backend-path = ["."] [tool.setuptools_scm] - -[tool.pytest-enabler.mypy] -# disabled diff --git a/setup.cfg b/setup.cfg index 91fb67724c6..3aa3a6a3234 100644 --- a/setup.cfg +++ b/setup.cfg @@ -47,9 +47,7 @@ testing = pytest-cov; \ # coverage seems to make PyPy extremely slow python_implementation != "PyPy" - pytest-mypy >= 0.9.1; \ - # workaround for jaraco/skeleton#22 - python_implementation != "PyPy" + pytest-mypy pytest-enabler >= 2.2 # workaround for pypa/setuptools#3921 pytest-ruff >= 0.2.1; sys_platform != "cygwin" @@ -66,6 +64,7 @@ testing = filelock>=3.4.0 ini2toml[lite]>=0.9 tomli-w>=1.0.0 + tomli pytest-timeout pytest-perf; \ # workaround for jaraco/inflect#195, pydantic/pydantic-core#773 (see #3986) @@ -73,6 +72,8 @@ testing = # for tools/finalize.py jaraco.develop >= 7.21; python_version >= "3.9" and sys_platform != "cygwin" pytest-home >= 0.5 + # No Python 3.12 dependencies require importlib_metadata, but needed for type-checking since we import it directly + importlib_metadata; python_version >= "3.12" testing-integration = pytest diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 1301433a327..b5c98c86dcd 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -16,7 +16,7 @@ try: # Attempt to use Cython for building extensions, if available - from Cython.Distutils.build_ext import build_ext as _build_ext + from Cython.Distutils.build_ext import build_ext as _build_ext # type: ignore[import-not-found] # Cython not installed on CI tests # Additionally, assert that the compiler module will load # also. Ref #1229. diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py index 24980edcf46..9d319398c91 100644 --- a/setuptools/command/editable_wheel.py +++ b/setuptools/command/editable_wheel.py @@ -59,7 +59,7 @@ from .install_scripts import install_scripts as install_scripts_cls if TYPE_CHECKING: - from wheel.wheelfile import WheelFile # noqa + from wheel.wheelfile import WheelFile # type:ignore[import-untyped] # noqa _P = TypeVar("_P", bound=StrPath) _logger = logging.getLogger(__name__) diff --git a/setuptools/config/_validate_pyproject/fastjsonschema_validations.py b/setuptools/config/_validate_pyproject/fastjsonschema_validations.py index b81d13c1190..8b852bbfd41 100644 --- a/setuptools/config/_validate_pyproject/fastjsonschema_validations.py +++ b/setuptools/config/_validate_pyproject/fastjsonschema_validations.py @@ -1,5 +1,4 @@ # noqa -# type: ignore # flake8: noqa # pylint: skip-file # mypy: ignore-errors