Skip to content

Commit e66c7ae

Browse files
committed
Config changes to use our custom stubs
1 parent 79c5db9 commit e66c7ae

18 files changed

+41
-45
lines changed

mypy.ini

Lines changed: 5 additions & 9 deletions
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,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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 0 additions & 5 deletions
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

setuptools/build_meta.py

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,5 @@ def do_egg_install(self) -> None:
180180
# XXX Python 3.1 doesn't see _nc if this is inside the class
181181
install.sub_commands = [
182182
cmd for cmd in orig.install.sub_commands if cmd[0] not in install._nc
183-
] + install.new_commands
183+
] + install.new_commands # type: ignore[operator]
184+
# TODO: Type sub_commands/new_commands to avoid variance issues in pypa/distutils (like python/typeshed#11951)

setuptools/command/install_lib.py

Lines changed: 3 additions & 4 deletions
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

0 commit comments

Comments
 (0)