Skip to content

Commit 1733d12

Browse files
committed
Config changes to use our custom stubs
1 parent 770395e commit 1733d12

12 files changed

+32
-38
lines changed

mypy.ini

+5-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.8
@@ -48,17 +51,10 @@ 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
ignore_missing_imports = True
57+
6258
# - The following are not marked as py.typed:
6359
# - jaraco: Since mypy 1.12, the root name of the untyped namespace package gets called-out too
6460
# - jaraco.develop: https://github.com/jaraco/jaraco.develop/issues/22

pyproject.toml

+4
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ type = [
133133

134134
# local
135135

136+
# Referenced in distutils-stubs
137+
"types-docutils",
136138
# pin mypy version so a new version doesn't suddenly cause the CI to fail,
137139
# until types-setuptools is removed from typeshed.
138140
# For help with static-typing issues, or mypy update, ping @Avasam
@@ -203,6 +205,8 @@ include-package-data = true
203205
include = [
204206
"setuptools*",
205207
"pkg_resources*",
208+
# TODO: Include distutils stubs with package once we're confident in them
209+
# "typings/distutils-stubs",
206210
"_distutils_hack*",
207211
]
208212
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.8",
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
@@ -34,6 +34,9 @@ ignore = [
3434
# Only enforcing return type annotations for public functions
3535
"ANN202", # missing-return-type-private-function
3636
"ANN204", # missing-return-type-special-method
37+
# Typeshed doesn't want complex or non-literal defaults for maintenance and testing reasons.
38+
# This doesn't affect us, let's have more complete stubs.
39+
"PYI011", # typed-argument-default-in-stub
3740

3841
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
3942
"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
224+
return cmd # pyright: ignore[reportReturnType] # pypa/distutils#307
230225

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

setuptools/command/build_py.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def finalize_options(self):
5050
del self.__dict__['data_files']
5151
self.__updated_files = []
5252

53-
def copy_file( # type: ignore[override] # No overload, str support only
53+
def copy_file(
5454
self,
5555
infile: StrPath,
5656
outfile: StrPath,
@@ -143,7 +143,7 @@ def find_data_files(self, package, src_dir):
143143
)
144144
return self.exclude_data_files(package, src_dir, files)
145145

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

setuptools/command/install.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,5 @@ def do_egg_install(self):
161161
# XXX Python 3.1 doesn't see _nc if this is inside the class
162162
install.sub_commands = [
163163
cmd for cmd in orig.install.sub_commands if cmd[0] not in install._nc
164-
] + install.new_commands
164+
] + install.new_commands # type: ignore[operator]
165+
# TODO: Type sub_commands/new_commands to avoid variance issues in pypa/distutils (like python/typeshed#11951)

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 and preserve_times and not preserve_symlinks

setuptools/command/sdist.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ class sdist(orig.sdist):
5050
]
5151

5252
distribution: Distribution # override distutils.dist.Distribution with setuptools.dist.Distribution
53-
negative_opt: ClassVar[dict[str, str]] = {}
53+
# TODO: Mark class-level mutables as ClassVars in pypa/distutils (like python/typeshed#12403)
54+
negative_opt: ClassVar[dict[str, str]] = {} # type: ignore[assignment]
5455

5556
README_EXTENSIONS = ['', '.rst', '.txt', '.md']
56-
READMES = tuple('README{0}'.format(ext) for ext in README_EXTENSIONS)
57+
# TODO: Mark class-level mutables as ClassVars in pypa/distutils (like python/typeshed#12403)
58+
READMES = tuple('README{0}'.format(ext) for ext in README_EXTENSIONS) # type: ignore[assignment]
5759

5860
def run(self):
5961
self.run_command('egg_info')

setuptools/config/setupcfg.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
Generic,
2525
Iterable,
2626
Iterator,
27-
List,
2827
Tuple,
2928
TypeVar,
30-
cast,
3129
)
3230

3331
from packaging.markers import default_environment as marker_env
@@ -112,8 +110,7 @@ def _apply(
112110
filenames = [*other_files, filepath]
113111

114112
try:
115-
# TODO: Temporary cast until mypy 1.12 is released with upstream fixes from typeshed
116-
_Distribution.parse_config_files(dist, filenames=cast(List[str], filenames))
113+
_Distribution.parse_config_files(dist, filenames=filenames)
117114
handlers = parse_configuration(
118115
dist, dist.command_options, ignore_option_errors=ignore_option_errors
119116
)

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
"""

0 commit comments

Comments
 (0)