Skip to content
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

Enable mypy on CI #4257

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ testing =
# for tools/finalize.py
jaraco.develop >= 7.21; python_version >= "3.9" and sys_platform != "cygwin"
pytest-home >= 0.5
# No Python 3.11 dependencies require tomli, but needed for type-checking since we import it directly
tomli
# No Python 3.12 dependencies require importlib_metadata, but needed for type-checking since we import it directly
importlib_metadata

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
Avasam marked this conversation as resolved.
Show resolved Hide resolved
# flake8: noqa
# pylint: skip-file
# mypy: ignore-errors
Expand Down
Loading