Skip to content

Commit 89b4401

Browse files
authored
Re-enable mypy and sync mypy.ini from skeleton (#4604)
2 parents 61a5a03 + 1429bf5 commit 89b4401

File tree

11 files changed

+50
-34
lines changed

11 files changed

+50
-34
lines changed

mypy.ini

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
[mypy]
2-
# CI should test for all versions, local development gets hints for oldest supported
3-
# But our testing setup doesn't allow passing CLI arguments, so local devs have to set this manually.
4-
# python_version = 3.8
2+
## upstream
3+
4+
# Is the project well-typed?
55
strict = False
6+
7+
# Early opt-in even when strict = False
68
warn_unused_ignores = True
79
warn_redundant_casts = True
8-
# required to support namespace packages: https://github.com/python/mypy/issues/14057
10+
enable_error_code = ignore-without-code
11+
12+
# Support namespace packages per https://github.com/python/mypy/issues/14057
913
explicit_package_bases = True
1014

1115
disable_error_code =
1216
# Disable due to many false positives
1317
overload-overlap,
1418

19+
## local
20+
21+
# CI should test for all versions, local development gets hints for oldest supported
22+
# But our testing setup doesn't allow passing CLI arguments, so local devs have to set this manually.
23+
# python_version = 3.8
24+
1525
exclude = (?x)(
1626
# Avoid scanning Python files in generated folders
1727
^build/
@@ -54,6 +64,6 @@ ignore_missing_imports = True
5464

5565
# Even when excluding a module, import issues can show up due to following import
5666
# https://github.com/python/mypy/issues/11936#issuecomment-1466764006
57-
[mypy-setuptools.config._validate_pyproject.*,setuptools._distutils.*]
67+
[mypy-setuptools.config._validate_pyproject.*,setuptools._vendor.*,setuptools._distutils.*]
5868
follow_imports = silent
5969
# silent => ignore errors when following imports

pkg_resources/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2777,7 +2777,7 @@ def load(
27772777
if require:
27782778
# We could pass `env` and `installer` directly,
27792779
# but keeping `*args` and `**kwargs` for backwards compatibility
2780-
self.require(*args, **kwargs) # type: ignore
2780+
self.require(*args, **kwargs) # type: ignore[arg-type]
27812781
return self.resolve()
27822782

27832783
def resolve(self) -> _ResolvedEntryPoint:

pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,3 @@ formats = "zip"
216216

217217

218218
[tool.setuptools_scm]
219-
220-
221-
[tool.pytest-enabler.mypy]
222-
# Disabled due to jaraco/skeleton#143

setuptools/build_meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def _build(cmd: list[str]):
431431
return _build(['bdist_wheel'])
432432

433433
try:
434-
return _build(['bdist_wheel', '--dist-info-dir', metadata_directory])
434+
return _build(['bdist_wheel', '--dist-info-dir', str(metadata_directory)])
435435
except SystemExit as ex: # pragma: nocover
436436
# pypa/setuptools#4683
437437
if "--dist-info-dir not recognized" not in str(ex):

setuptools/config/expand.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ def _load_spec(spec: ModuleSpec, module_name: str) -> ModuleType:
203203
return sys.modules[name]
204204
module = importlib.util.module_from_spec(spec)
205205
sys.modules[name] = module # cache (it also ensures `==` works on loaded items)
206-
spec.loader.exec_module(module) # type: ignore
206+
assert spec.loader is not None
207+
spec.loader.exec_module(module)
207208
return module
208209

209210

@@ -285,10 +286,11 @@ def find_packages(
285286

286287
from setuptools.discovery import construct_package_dir
287288

288-
if namespaces:
289-
from setuptools.discovery import PEP420PackageFinder as PackageFinder
289+
# check "not namespaces" first due to python/mypy#6232
290+
if not namespaces:
291+
from setuptools.discovery import PackageFinder
290292
else:
291-
from setuptools.discovery import PackageFinder # type: ignore
293+
from setuptools.discovery import PEP420PackageFinder as PackageFinder
292294

293295
root_dir = root_dir or os.curdir
294296
where = kwargs.pop('where', ['.'])
@@ -359,7 +361,8 @@ def entry_points(text: str, text_source="entry-points") -> dict[str, dict]:
359361
entry-point names, and the second level values are references to objects
360362
(that correspond to the entry-point value).
361363
"""
362-
parser = ConfigParser(default_section=None, delimiters=("=",)) # type: ignore
364+
# Using undocumented behaviour, see python/typeshed#12700
365+
parser = ConfigParser(default_section=None, delimiters=("=",)) # type: ignore[call-overload]
363366
parser.optionxform = str # case sensitive
364367
parser.read_string(text, text_source)
365368
groups = {k: dict(v.items()) for k, v in parser.items()}

setuptools/config/pyprojecttoml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def validate(config: dict, filepath: StrPath) -> bool:
4444

4545
trove_classifier = validator.FORMAT_FUNCTIONS.get("trove-classifier")
4646
if hasattr(trove_classifier, "_disable_download"):
47-
# Improve reproducibility by default. See issue 31 for validate-pyproject.
48-
trove_classifier._disable_download() # type: ignore
47+
# Improve reproducibility by default. See abravalheri/validate-pyproject#31
48+
trove_classifier._disable_download() # type: ignore[union-attr]
4949

5050
try:
5151
return validator.validate(config)

setuptools/config/setupcfg.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
List,
2828
Tuple,
2929
TypeVar,
30-
Union,
3130
cast,
3231
)
3332

@@ -53,7 +52,7 @@
5352
while the second element of the tuple is the option value itself
5453
"""
5554
AllCommandOptions = Dict["str", SingleCommandOptions] # cmd name => its options
56-
Target = TypeVar("Target", bound=Union["Distribution", "DistributionMetadata"])
55+
Target = TypeVar("Target", "Distribution", "DistributionMetadata")
5756

5857

5958
def read_configuration(
@@ -96,7 +95,7 @@ def _apply(
9695
filepath: StrPath,
9796
other_files: Iterable[StrPath] = (),
9897
ignore_option_errors: bool = False,
99-
) -> tuple[ConfigHandler, ...]:
98+
) -> tuple[ConfigMetadataHandler, ConfigOptionsHandler]:
10099
"""Read configuration from ``filepath`` and applies to the ``dist`` object."""
101100
from setuptools.dist import _Distribution
102101

@@ -122,7 +121,7 @@ def _apply(
122121
return handlers
123122

124123

125-
def _get_option(target_obj: Target, key: str):
124+
def _get_option(target_obj: Distribution | DistributionMetadata, key: str):
126125
"""
127126
Given a target object and option key, get that option from
128127
the target object, either through a get_{key} method or
@@ -134,10 +133,14 @@ def _get_option(target_obj: Target, key: str):
134133
return getter()
135134

136135

137-
def configuration_to_dict(handlers: tuple[ConfigHandler, ...]) -> dict:
136+
def configuration_to_dict(
137+
handlers: Iterable[
138+
ConfigHandler[Distribution] | ConfigHandler[DistributionMetadata]
139+
],
140+
) -> dict:
138141
"""Returns configuration data gathered by given handlers as a dict.
139142
140-
:param list[ConfigHandler] handlers: Handlers list,
143+
:param Iterable[ConfigHandler] handlers: Handlers list,
141144
usually from parse_configuration()
142145
143146
:rtype: dict
@@ -254,7 +257,7 @@ def __init__(
254257
ensure_discovered: expand.EnsurePackagesDiscovered,
255258
):
256259
self.ignore_option_errors = ignore_option_errors
257-
self.target_obj = target_obj
260+
self.target_obj: Target = target_obj
258261
self.sections = dict(self._section_options(options))
259262
self.set_options: list[str] = []
260263
self.ensure_discovered = ensure_discovered

setuptools/msvc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ def VCRuntimeRedist(self) -> str | None:
14181418
os.path.join(prefix, arch_subdir, crt_dir, vcruntime)
14191419
for (prefix, crt_dir) in itertools.product(prefixes, crt_dirs)
14201420
)
1421-
return next(filter(os.path.isfile, candidate_paths), None)
1421+
return next(filter(os.path.isfile, candidate_paths), None) # type: ignore[arg-type] #python/mypy#12682
14221422

14231423
def return_env(self, exists=True):
14241424
"""

setuptools/tests/config/test_setupcfg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88
from packaging.requirements import InvalidRequirement
99

10-
from setuptools.config.setupcfg import ConfigHandler, read_configuration
10+
from setuptools.config.setupcfg import ConfigHandler, Target, read_configuration
1111
from setuptools.dist import Distribution, _Distribution
1212
from setuptools.warnings import SetuptoolsDeprecationWarning
1313

@@ -16,7 +16,7 @@
1616
from distutils.errors import DistutilsFileError, DistutilsOptionError
1717

1818

19-
class ErrConfigHandler(ConfigHandler):
19+
class ErrConfigHandler(ConfigHandler[Target]):
2020
"""Erroneous handler. Fails to implement required methods."""
2121

2222
section_prefix = "**err**"

setuptools/tests/test_build_ext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def get_build_ext_cmd(self, optional: bool, **opts):
183183
"eggs.c": "#include missingheader.h\n",
184184
".build": {"lib": {}, "tmp": {}},
185185
}
186-
path.build(files) # type: ignore[arg-type] # jaraco/path#232
186+
path.build(files) # jaraco/path#232
187187
extension = Extension('spam.eggs', ['eggs.c'], optional=optional)
188188
dist = Distribution(dict(ext_modules=[extension]))
189189
dist.script_name = 'setup.py'

0 commit comments

Comments
 (0)