Skip to content

Commit aa0ad57

Browse files
committed
Merge typeshed return annotations
1 parent af53533 commit aa0ad57

24 files changed

+133
-108
lines changed

setuptools/__init__.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ def _fetch_build_eggs(dist: Distribution):
110110
raise
111111

112112

113-
def setup(**attrs):
113+
def setup(**attrs) -> Distribution:
114114
logging.configure()
115115
# Make sure we have any requirements needed to interpret 'attrs'.
116116
_install_setup_requires(attrs)
117-
return distutils.core.setup(**attrs)
117+
# Override return type of distutils.core.Distribution with setuptools.dist.Distribution
118+
return distutils.core.setup(**attrs) # type: ignore[return-value]
118119

119120

120121
setup.__doc__ = distutils.core.setup.__doc__
@@ -216,14 +217,14 @@ def ensure_string_list(self, option: str) -> None:
216217
@overload
217218
def reinitialize_command(
218219
self, command: str, reinit_subcommands: bool = False, **kw
219-
) -> _Command: ...
220+
) -> Command: ... # override distutils.cmd.Command with setuptools.Command
220221
@overload
221222
def reinitialize_command(
222223
self, command: _CommandT, reinit_subcommands: bool = False, **kw
223224
) -> _CommandT: ...
224225
def reinitialize_command(
225226
self, command: str | _Command, reinit_subcommands: bool = False, **kw
226-
) -> _Command:
227+
) -> Command | _Command:
227228
cmd = _Command.reinitialize_command(self, command, reinit_subcommands)
228229
vars(cmd).update(kw)
229230
return cmd # pyright: ignore[reportReturnType] # pypa/distutils#307

setuptools/build_meta.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import warnings
4040
from collections.abc import Iterable, Iterator, Mapping
4141
from pathlib import Path
42-
from typing import TYPE_CHECKING, Union
42+
from typing import TYPE_CHECKING, NoReturn, Union
4343

4444
import setuptools
4545

@@ -77,14 +77,14 @@ def __init__(self, specifiers) -> None:
7777

7878

7979
class Distribution(setuptools.dist.Distribution):
80-
def fetch_build_eggs(self, specifiers):
80+
def fetch_build_eggs(self, specifiers) -> NoReturn:
8181
specifier_list = list(parse_strings(specifiers))
8282

8383
raise SetupRequirementsError(specifier_list)
8484

8585
@classmethod
8686
@contextlib.contextmanager
87-
def patch(cls):
87+
def patch(cls) -> Iterator[None]:
8888
"""
8989
Replace
9090
distutils.dist.Distribution with this class
@@ -307,7 +307,7 @@ def _get_build_requires(
307307

308308
return requirements
309309

310-
def run_setup(self, setup_script: str = 'setup.py'):
310+
def run_setup(self, setup_script: str = 'setup.py') -> None:
311311
# Note that we can reuse our build directory between calls
312312
# Correctness comes first, then optimization later
313313
__file__ = os.path.abspath(setup_script)
@@ -330,10 +330,14 @@ def run_setup(self, setup_script: str = 'setup.py'):
330330
"setup-py-deprecated.html",
331331
)
332332

333-
def get_requires_for_build_wheel(self, config_settings: _ConfigSettings = None):
333+
def get_requires_for_build_wheel(
334+
self, config_settings: _ConfigSettings = None
335+
) -> list[str]:
334336
return self._get_build_requires(config_settings, requirements=[])
335337

336-
def get_requires_for_build_sdist(self, config_settings: _ConfigSettings = None):
338+
def get_requires_for_build_sdist(
339+
self, config_settings: _ConfigSettings = None
340+
) -> list[str]:
337341
return self._get_build_requires(config_settings, requirements=[])
338342

339343
def _bubble_up_info_directory(
@@ -364,7 +368,7 @@ def _find_info_directory(self, metadata_directory: StrPath, suffix: str) -> Path
364368

365369
def prepare_metadata_for_build_wheel(
366370
self, metadata_directory: StrPath, config_settings: _ConfigSettings = None
367-
):
371+
) -> str:
368372
sys.argv = [
369373
*sys.argv[:1],
370374
*self._global_args(config_settings),
@@ -420,7 +424,7 @@ def build_wheel(
420424
wheel_directory: StrPath,
421425
config_settings: _ConfigSettings = None,
422426
metadata_directory: StrPath | None = None,
423-
):
427+
) -> str:
424428
def _build(cmd: list[str]):
425429
with suppress_known_deprecation():
426430
return self._build_with_temp_dir(
@@ -445,7 +449,7 @@ def _build(cmd: list[str]):
445449

446450
def build_sdist(
447451
self, sdist_directory: StrPath, config_settings: _ConfigSettings = None
448-
):
452+
) -> str:
449453
return self._build_with_temp_dir(
450454
['sdist', '--formats', 'gztar'], '.tar.gz', sdist_directory, config_settings
451455
)
@@ -467,7 +471,7 @@ def build_editable(
467471
wheel_directory: StrPath,
468472
config_settings: _ConfigSettings = None,
469473
metadata_directory: StrPath | None = None,
470-
):
474+
) -> str:
471475
# XXX can or should we hide our editable_wheel command normally?
472476
info_dir = self._get_dist_info_dir(metadata_directory)
473477
opts = ["--dist-info-dir", info_dir] if info_dir else []
@@ -479,12 +483,12 @@ def build_editable(
479483

480484
def get_requires_for_build_editable(
481485
self, config_settings: _ConfigSettings = None
482-
):
486+
) -> list[str]:
483487
return self.get_requires_for_build_wheel(config_settings)
484488

485489
def prepare_metadata_for_build_editable(
486490
self, metadata_directory: StrPath, config_settings: _ConfigSettings = None
487-
):
491+
) -> str:
488492
return self.prepare_metadata_for_build_wheel(
489493
metadata_directory, config_settings
490494
)
@@ -502,7 +506,7 @@ class _BuildMetaLegacyBackend(_BuildMetaBackend):
502506
and will eventually be removed.
503507
"""
504508

505-
def run_setup(self, setup_script: str = 'setup.py'):
509+
def run_setup(self, setup_script: str = 'setup.py') -> None:
506510
# In order to maintain compatibility with scripts assuming that
507511
# the setup.py script is in a directory on the PYTHONPATH, inject
508512
# '' into sys.path. (pypa/setuptools#1642)

setuptools/command/bdist_egg.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@
99
import re
1010
import sys
1111
import textwrap
12+
from collections.abc import Iterator
1213
from sysconfig import get_path, get_python_version
1314
from types import CodeType
14-
from typing import TYPE_CHECKING, Literal
15+
from typing import TYPE_CHECKING, AnyStr, Literal
1516

1617
from setuptools import Command
1718
from setuptools.extension import Library
1819

19-
from .._path import StrPathT, ensure_directory
20+
from .._path import StrPath, StrPathT, ensure_directory
2021

2122
from distutils import log
2223
from distutils.dir_util import mkpath, remove_tree
2324

2425
if TYPE_CHECKING:
26+
from _typeshed import GenericPath
2527
from typing_extensions import TypeAlias
2628

2729
# Same as zipfile._ZipFileMode from typeshed
@@ -40,7 +42,9 @@ def strip_module(filename):
4042
return filename
4143

4244

43-
def sorted_walk(dir):
45+
def sorted_walk(
46+
dir: GenericPath[AnyStr],
47+
) -> Iterator[tuple[AnyStr, list[AnyStr], list[AnyStr]]]:
4448
"""Do os.walk in a reproducible way,
4549
independent of indeterministic filesystem readdir order
4650
"""
@@ -163,7 +167,7 @@ def call_command(self, cmdname, **kw):
163167
self.run_command(cmdname)
164168
return cmd
165169

166-
def run(self): # noqa: C901 # is too complex (14) # FIXME
170+
def run(self) -> None: # noqa: C901 # is too complex (14) # FIXME
167171
# Generate metadata first
168172
self.run_command("egg_info")
169173
# We run install_lib before install_data, because some data hacks
@@ -247,7 +251,7 @@ def run(self): # noqa: C901 # is too complex (14) # FIXME
247251
self.egg_output,
248252
))
249253

250-
def zap_pyfiles(self):
254+
def zap_pyfiles(self) -> None:
251255
log.info("Removing .py files from temporary directory")
252256
for base, dirs, files in walk_egg(self.bdist_dir):
253257
for name in files:
@@ -325,7 +329,7 @@ def get_ext_outputs(self):
325329
NATIVE_EXTENSIONS: dict[str, None] = dict.fromkeys('.dll .so .dylib .pyd'.split())
326330

327331

328-
def walk_egg(egg_dir):
332+
def walk_egg(egg_dir: StrPath) -> Iterator[tuple[str, list[str], list[str]]]:
329333
"""Walk an unpacked egg's contents, skipping the metadata directory"""
330334
walker = sorted_walk(egg_dir)
331335
base, dirs, files = next(walker)
@@ -411,7 +415,7 @@ def scan_module(egg_dir, base, name, stubs):
411415
return safe
412416

413417

414-
def iter_symbols(code):
418+
def iter_symbols(code: CodeType) -> Iterator[str]:
415419
"""Yield names and strings used by `code` and its nested code objects"""
416420
yield from code.co_names
417421
for const in code.co_consts:

setuptools/command/bdist_wheel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def get_tag(self) -> tuple[str, str, str]:
391391
)
392392
return tag
393393

394-
def run(self):
394+
def run(self) -> None:
395395
build_scripts = self.reinitialize_command("build_scripts")
396396
build_scripts.executable = "python"
397397
build_scripts.force = True

setuptools/command/build_ext.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class build_ext(_build_ext):
9393
editable_mode = False
9494
inplace = False
9595

96-
def run(self):
96+
def run(self) -> None:
9797
"""Build extensions in build directory, then copy if --inplace"""
9898
old_inplace, self.inplace = self.inplace, 0
9999
_build_ext.run(self)
@@ -223,7 +223,7 @@ def finalize_options(self) -> None:
223223
if self.editable_mode:
224224
self.inplace = True
225225

226-
def setup_shlib_compiler(self):
226+
def setup_shlib_compiler(self) -> None:
227227
compiler = self.shlib_compiler = new_compiler(
228228
compiler=self.compiler, dry_run=self.dry_run, force=self.force
229229
)

setuptools/command/build_py.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class build_py(orig.build_py):
4141
editable_mode: bool = False
4242
existing_egg_info_dir: str | None = None #: Private API, internal use only.
4343

44-
def finalize_options(self):
44+
def finalize_options(self) -> None:
4545
orig.build_py.finalize_options(self)
4646
self.package_data = self.distribution.package_data
4747
self.exclude_package_data = self.distribution.exclude_package_data or {}
@@ -100,7 +100,7 @@ def _get_data_files(self):
100100
self.analyze_manifest()
101101
return list(map(self._get_pkg_data_files, self.packages or ()))
102102

103-
def get_data_files_without_manifest(self):
103+
def get_data_files_without_manifest(self) -> list[tuple[str, str, str, list[str]]]:
104104
"""
105105
Generate list of ``(package,src_dir,build_dir,filenames)`` tuples,
106106
but without triggering any attempt to analyze or build the manifest.
@@ -110,7 +110,7 @@ def get_data_files_without_manifest(self):
110110
self.__dict__.setdefault('manifest_files', {})
111111
return list(map(self._get_pkg_data_files, self.packages or ()))
112112

113-
def _get_pkg_data_files(self, package):
113+
def _get_pkg_data_files(self, package: str) -> tuple[str, str, str, list[str]]:
114114
# Locate package source directory
115115
src_dir = self.get_package_dir(package)
116116

@@ -178,7 +178,7 @@ def build_package_data(self) -> None:
178178
_outf, _copied = self.copy_file(srcfile, target)
179179
make_writable(target)
180180

181-
def analyze_manifest(self):
181+
def analyze_manifest(self) -> None:
182182
self.manifest_files = mf = {}
183183
if not self.distribution.include_package_data:
184184
return
@@ -277,7 +277,7 @@ def initialize_options(self):
277277
self.editable_mode = False
278278
self.existing_egg_info_dir = None
279279

280-
def get_package_dir(self, package):
280+
def get_package_dir(self, package: str) -> str:
281281
res = orig.build_py.get_package_dir(self, package)
282282
if self.distribution.src_root is not None:
283283
return os.path.join(self.distribution.src_root, res)

setuptools/command/develop.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class develop(namespaces.DevelopInstaller, easy_install):
2626

2727
command_consumes_arguments = False # override base
2828

29-
def run(self):
29+
def run(self) -> None:
3030
if self.uninstall:
3131
self.multi_version = True
3232
self.uninstall_link()

setuptools/command/easy_install.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def _render_version():
239239
print(f'setuptools {dist.version} from {dist.location} (Python {ver})')
240240
raise SystemExit
241241

242-
def finalize_options(self): # noqa: C901 # is too complex (25) # FIXME
242+
def finalize_options(self) -> None: # noqa: C901 # is too complex (25) # FIXME
243243
self.version and self._render_version()
244244

245245
py_version = sys.version.split()[0]
@@ -748,7 +748,7 @@ def install_item(
748748
return dist
749749
return None
750750

751-
def select_scheme(self, name):
751+
def select_scheme(self, name) -> None:
752752
try:
753753
install._select_scheme(self, name)
754754
except AttributeError:

setuptools/command/editable_wheel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ def _empty_dir(dir_: _P) -> _P:
779779

780780

781781
class _NamespaceInstaller(namespaces.Installer):
782-
def __init__(self, distribution, installation_dir, editable_name, src_root):
782+
def __init__(self, distribution, installation_dir, editable_name, src_root) -> None:
783783
self.distribution = distribution
784784
self.src_root = src_root
785785
self.installation_dir = installation_dir

setuptools/command/egg_info.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
Create a distribution's .egg-info directory and contents"""
44

5+
from __future__ import annotations
6+
57
import functools
68
import os
79
import re
@@ -195,11 +197,11 @@ def initialize_options(self):
195197
# allow the 'tag_svn_revision' to be detected and
196198
# set, supporting sdists built on older Setuptools.
197199
@property
198-
def tag_svn_revision(self) -> None:
200+
def tag_svn_revision(self) -> int | None:
199201
pass
200202

201203
@tag_svn_revision.setter
202-
def tag_svn_revision(self, value):
204+
def tag_svn_revision(self, value) -> None:
203205
pass
204206

205207
####################################
@@ -330,7 +332,7 @@ def __init__(
330332
super().__init__(warn, debug_print)
331333
self.ignore_egg_info_dir = ignore_egg_info_dir
332334

333-
def process_template_line(self, line):
335+
def process_template_line(self, line) -> None:
334336
# Parse the line: split it up, make sure the right number of words
335337
# is there, and return the relevant words. 'action' is always
336338
# defined: it's the first word of the line. Which of the other

setuptools/command/install_egg_info.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class install_egg_info(namespaces.Installer, Command):
2020
def initialize_options(self):
2121
self.install_dir = None
2222

23-
def finalize_options(self):
23+
def finalize_options(self) -> None:
2424
self.set_undefined_options('install_lib', ('install_dir', 'install_dir'))
2525
ei_cmd = self.get_finalized_command("egg_info")
2626
basename = f"{ei_cmd._get_egg_basename()}.egg-info"

setuptools/command/saveopts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class saveopts(option_base):
66

77
description = "save supplied options to setup.cfg or other config file"
88

9-
def run(self):
9+
def run(self) -> None:
1010
dist = self.distribution
1111
settings = {}
1212

setuptools/command/sdist.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import contextlib
44
import os
55
import re
6+
from collections.abc import Iterator
67
from itertools import chain
78
from typing import ClassVar
89

@@ -16,7 +17,7 @@
1617
_default_revctrl = list
1718

1819

19-
def walk_revctrl(dirname=''):
20+
def walk_revctrl(dirname='') -> Iterator:
2021
"""Find all files under revision control"""
2122
for ep in metadata.entry_points(group='setuptools.file_finders'):
2223
yield from ep.load()(dirname)
@@ -195,7 +196,7 @@ def _manifest_is_not_generated(self):
195196
first_line = fp.readline()
196197
return first_line != b'# file GENERATED by distutils, do NOT edit\n'
197198

198-
def read_manifest(self):
199+
def read_manifest(self) -> None:
199200
"""Read the manifest file (named by 'self.manifest') and use it to
200201
fill in 'self.filelist', the list of files to include in the source
201202
distribution.

0 commit comments

Comments
 (0)