Skip to content

Commit

Permalink
Turn on mypy type-checking in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Mar 5, 2024
1 parent b39639a commit 2ee6ac9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 32 deletions.
37 changes: 14 additions & 23 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ build-backend = "setuptools.build_meta"
backend-path = ["."]

[tool.setuptools_scm]

[tool.pytest-enabler.mypy]
# disabled
7 changes: 4 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -66,13 +64,16 @@ 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)
sys_platform != "cygwin"
# 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
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/editable_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# noqa
# type: ignore
# flake8: noqa
# pylint: skip-file
# mypy: ignore-errors
Expand Down

0 comments on commit 2ee6ac9

Please sign in to comment.