Skip to content

Commit 0f98b7e

Browse files
committed
Config and comments changes to use our custom stubs
1 parent 90c90a3 commit 0f98b7e

17 files changed

+37
-43
lines changed

mypy.ini

+4-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
strict = False
66

77
# Early opt-in even when strict = False
8-
# warn_unused_ignores = True # Disabled until we have distutils stubs for Python 3.12+
8+
warn_unused_ignores = True
99
warn_redundant_casts = True
1010
enable_error_code = ignore-without-code
1111

@@ -18,6 +18,9 @@ disable_error_code =
1818

1919
## local
2020

21+
# Use our custom stubs for distutils
22+
mypy_path = $MYPY_CONFIG_FILE_DIR/typings
23+
2124
# CI should test for all versions, local development gets hints for oldest supported
2225
# But our testing setup doesn't allow passing CLI arguments, so local devs have to set this manually.
2326
# python_version = 3.9
@@ -48,14 +51,6 @@ disable_error_code =
4851
[mypy-pkg_resources.tests.*]
4952
disable_error_code = import-not-found
5053

51-
# - distutils doesn't exist on Python 3.12, unfortunately, this means typing
52-
# will be missing for subclasses of distutils on Python 3.12 until either:
53-
# - support for `SETUPTOOLS_USE_DISTUTILS=stdlib` is dropped (#3625)
54-
# for setuptools to import `_distutils` directly
55-
# - or non-stdlib distutils typings are exposed
56-
[mypy-distutils.*]
57-
ignore_missing_imports = True
58-
5954
# - wheel: does not intend on exposing a programmatic API https://github.com/pypa/wheel/pull/610#issuecomment-2081687671
6055
[mypy-wheel.*]
6156
follow_untyped_imports = True

pyproject.toml

+4
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ type = [
132132

133133
# local
134134

135+
# Referenced in distutils-stubs
136+
"types-docutils",
135137
# pin mypy version so a new version doesn't suddenly cause the CI to fail,
136138
# until types-setuptools is removed from typeshed.
137139
# For help with static-typing issues, or mypy update, ping @Avasam
@@ -202,6 +204,8 @@ include-package-data = true
202204
include = [
203205
"setuptools*",
204206
"pkg_resources*",
207+
# TODO: Include distutils stubs with package once we're confident in them
208+
# "typings/distutils-stubs",
205209
"_distutils_hack*",
206210
]
207211
exclude = [

pyrightconfig.json

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
],
1313
// Our testing setup doesn't allow passing CLI arguments, so local devs have to set this manually.
1414
// "pythonVersion": "3.9",
15+
// Allow using distutils-stubs on Python 3.12+
16+
"reportMissingModuleSource": false,
1517
// For now we don't mind if mypy's `type: ignore` comments accidentally suppresses pyright issues
1618
"enableTypeIgnoreComments": true,
1719
"typeCheckingMode": "basic",

ruff.toml

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ ignore = [
4545
# Only enforcing return type annotations for public functions
4646
"ANN202", # missing-return-type-private-function
4747
"ANN204", # missing-return-type-special-method
48+
# Typeshed doesn't want complex or non-literal defaults for maintenance and testing reasons.
49+
# This doesn't affect us, let's have more complete stubs.
50+
"PYI011", # typed-argument-default-in-stub
4851

4952
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
5053
"W191",

setuptools/__init__.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
"""Extensions to the 'distutils' for large or complex distributions"""
2-
# mypy: disable_error_code=override
3-
# Command.reinitialize_command has an extra **kw param that distutils doesn't have
4-
# Can't disable on the exact line because distutils doesn't exists on Python 3.12
5-
# and mypy isn't aware of distutils_hack, causing distutils.core.Command to be Any,
6-
# and a [unused-ignore] to be raised on 3.12+
72

83
from __future__ import annotations
94

@@ -226,7 +221,7 @@ def reinitialize_command(
226221
) -> _Command:
227222
cmd = _Command.reinitialize_command(self, command, reinit_subcommands)
228223
vars(cmd).update(kw)
229-
return cmd # pyright: ignore[reportReturnType] # pypa/distutils#307
224+
return cmd
230225

231226
@abstractmethod
232227
def initialize_options(self) -> None:

setuptools/build_meta.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ def patch(cls):
9191
for the duration of this context.
9292
"""
9393
orig = distutils.core.Distribution
94-
distutils.core.Distribution = cls # type: ignore[misc] # monkeypatching
94+
distutils.core.Distribution = cls
9595
try:
9696
yield
9797
finally:
98-
distutils.core.Distribution = orig # type: ignore[misc] # monkeypatching
98+
distutils.core.Distribution = orig
9999

100100

101101
@contextlib.contextmanager

setuptools/command/build_ext.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def setup_shlib_compiler(self):
248248
compiler.set_link_objects(self.link_objects)
249249

250250
# hack so distutils' build_extension() builds a library instead
251-
compiler.link_shared_object = link_shared_object.__get__(compiler) # type: ignore[method-assign]
251+
compiler.link_shared_object = link_shared_object.__get__(compiler)
252252

253253
def get_export_symbols(self, ext):
254254
if isinstance(ext, Library):

setuptools/command/build_py.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def finalize_options(self):
4848
if 'data_files' in self.__dict__:
4949
del self.__dict__['data_files']
5050

51-
def copy_file( # type: ignore[override] # No overload, no bytes support
51+
def copy_file(
5252
self,
5353
infile: StrPath,
5454
outfile: StrPathT,
@@ -135,7 +135,7 @@ def find_data_files(self, package, src_dir):
135135
)
136136
return self.exclude_data_files(package, src_dir, files)
137137

138-
def get_outputs(self, include_bytecode: bool = True) -> list[str]: # type: ignore[override] # Using a real boolean instead of 0|1
138+
def get_outputs(self, include_bytecode: bool = True) -> list[str]:
139139
"""See :class:`setuptools.commands.build.SubCommand`"""
140140
if self.editable_mode:
141141
return list(self.get_output_mapping().keys())

setuptools/command/install_lib.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ def copy_tree(
9595
self,
9696
infile: StrPath,
9797
outfile: str,
98-
# override: Using actual booleans
99-
preserve_mode: bool = True, # type: ignore[override]
100-
preserve_times: bool = True, # type: ignore[override]
101-
preserve_symlinks: bool = False, # type: ignore[override]
98+
preserve_mode: bool = True,
99+
preserve_times: bool = True,
100+
preserve_symlinks: bool = False,
102101
level: object = 1,
103102
) -> list[str]:
104103
assert preserve_mode

setuptools/command/setopt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def edit_config(filename, settings, dry_run=False):
3737
"""
3838
log.debug("Reading configuration from %s", filename)
3939
opts = configparser.RawConfigParser()
40-
opts.optionxform = lambda optionstr: optionstr # type: ignore[method-assign] # overriding method
40+
opts.optionxform = lambda optionstr: optionstr
4141
_cfg_read_utf8_with_fallback(opts, filename)
4242

4343
for section, options in settings.items():

setuptools/config/setupcfg.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from collections import defaultdict
1818
from collections.abc import Iterable, Iterator
1919
from functools import partial, wraps
20-
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Generic, TypeVar, cast
20+
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Generic, TypeVar
2121

2222
from packaging.markers import default_environment as marker_env
2323
from packaging.requirements import InvalidRequirement, Requirement
@@ -101,8 +101,7 @@ def _apply(
101101
filenames = [*other_files, filepath]
102102

103103
try:
104-
# TODO: Temporary cast until mypy 1.12 is released with upstream fixes from typeshed
105-
_Distribution.parse_config_files(dist, filenames=cast(list[str], filenames))
104+
_Distribution.parse_config_files(dist, filenames=filenames)
106105
handlers = parse_configuration(
107106
dist, dist.command_options, ignore_option_errors=ignore_option_errors
108107
)

setuptools/dist.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ def fetch_build_egg(self, req):
723723

724724
return fetch_build_egg(self, req)
725725

726-
def get_command_class(self, command: str) -> type[distutils.cmd.Command]: # type: ignore[override] # Not doing complex overrides yet
726+
def get_command_class(self, command: str) -> type[distutils.cmd.Command]:
727727
"""Pluggable version of get_command_class()"""
728728
if command in self.cmdclass:
729729
return self.cmdclass[command]

setuptools/errors.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
BaseError = _distutils_errors.DistutilsError
3131

3232

33-
class InvalidConfigError(OptionError): # type: ignore[valid-type, misc] # distutils imports are `Any` on python 3.12+
33+
class InvalidConfigError(OptionError):
3434
"""Error used for invalid configurations."""
3535

3636

37-
class RemovedConfigError(OptionError): # type: ignore[valid-type, misc] # distutils imports are `Any` on python 3.12+
37+
class RemovedConfigError(OptionError):
3838
"""Error used for configurations that were deprecated and removed."""
3939

4040

41-
class RemovedCommandError(BaseError, RuntimeError): # type: ignore[valid-type, misc] # distutils imports are `Any` on python 3.12+
41+
class RemovedCommandError(BaseError, RuntimeError):
4242
"""Error used for commands that have been removed in setuptools.
4343
4444
Since ``setuptools`` is built on ``distutils``, simply removing a command
@@ -48,7 +48,7 @@ class RemovedCommandError(BaseError, RuntimeError): # type: ignore[valid-type,
4848
"""
4949

5050

51-
class PackageDiscoveryError(BaseError, RuntimeError): # type: ignore[valid-type, misc] # distutils imports are `Any` on python 3.12+
51+
class PackageDiscoveryError(BaseError, RuntimeError):
5252
"""Impossible to perform automatic discovery of packages and/or modules.
5353
5454
The current project layout or given discovery options can lead to problems when

setuptools/extension.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,7 @@ def __init__(
151151
# The *args is needed for compatibility as calls may use positional
152152
# arguments. py_limited_api may be set only via keyword.
153153
self.py_limited_api = py_limited_api
154-
super().__init__(
155-
name,
156-
sources, # type: ignore[arg-type] # Vendored version of setuptools supports PathLike
157-
*args,
158-
**kw,
159-
)
154+
super().__init__(name, sources, *args, **kw)
160155

161156
def _convert_pyx_sources_to_lang(self):
162157
"""

setuptools/logging.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def configure() -> None:
3232
# and then loaded again when patched,
3333
# implying: id(distutils.log) != id(distutils.dist.log).
3434
# Make sure the same module object is used everywhere:
35-
distutils.dist.log = distutils.log
35+
distutils.dist.log = distutils.log # type: ignore[assignment]
3636

3737

3838
def set_threshold(level: int) -> int:

setuptools/monkey.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def patch_all():
7373
import setuptools
7474

7575
# we can't patch distutils.cmd, alas
76-
distutils.core.Command = setuptools.Command # type: ignore[misc,assignment] # monkeypatching
76+
distutils.core.Command = setuptools.Command
7777

7878
_patch_distribution_metadata()
7979

@@ -82,8 +82,8 @@ def patch_all():
8282
module.Distribution = setuptools.dist.Distribution
8383

8484
# Install the patched Extension
85-
distutils.core.Extension = setuptools.extension.Extension # type: ignore[misc,assignment] # monkeypatching
86-
distutils.extension.Extension = setuptools.extension.Extension # type: ignore[misc,assignment] # monkeypatching
85+
distutils.core.Extension = setuptools.extension.Extension
86+
distutils.extension.Extension = setuptools.extension.Extension
8787
if 'distutils.command.build_ext' in sys.modules:
8888
sys.modules[
8989
'distutils.command.build_ext'

setuptools/tests/test_build_ext.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24
import sys
35
from importlib.util import cache_from_source as _compiled_file_name

0 commit comments

Comments
 (0)