Skip to content

Commit eea59f6

Browse files
authored
Update setuptools return types (#12991)
1 parent 480b1ac commit eea59f6

17 files changed

+69
-70
lines changed

stubs/setuptools/setuptools/__init__.pyi

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from _typeshed import Incomplete, StrPath
1+
from _typeshed import Incomplete
22
from abc import abstractmethod
3-
from collections.abc import Iterable, Mapping, Sequence
3+
from collections.abc import Mapping, Sequence
44
from typing import Any, Literal, TypedDict, TypeVar, overload, type_check_only
55
from typing_extensions import NotRequired
66

@@ -27,6 +27,7 @@ from .command.saveopts import saveopts
2727
from .command.sdist import sdist
2828
from .command.setopt import setopt
2929
from .depends import Require as Require
30+
from .discovery import _Finder
3031
from .dist import Distribution as Distribution
3132
from .extension import Extension as Extension
3233
from .warnings import SetuptoolsDeprecationWarning as SetuptoolsDeprecationWarning
@@ -54,11 +55,9 @@ class _BuildInfo(TypedDict):
5455
include_dirs: NotRequired[list[str]]
5556
cflags: NotRequired[list[str]]
5657

57-
# Pytype fails with the following:
58-
# find_packages = PackageFinder.find
59-
# find_namespace_packages = PEP420PackageFinder.find
60-
def find_packages(where: StrPath = ".", exclude: Iterable[str] = (), include: Iterable[str] = ("*",)) -> list[str]: ...
61-
def find_namespace_packages(where: StrPath = ".", exclude: Iterable[str] = (), include: Iterable[str] = ("*",)) -> list[str]: ...
58+
find_packages = _Finder.find
59+
find_namespace_packages = _Finder.find
60+
6261
def setup(
6362
*,
6463
name: str = ...,

stubs/setuptools/setuptools/build_meta.pyi

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from _typeshed import Incomplete, StrPath
22
from collections.abc import Mapping
3+
from contextlib import _GeneratorContextManager
4+
from typing import NoReturn
35
from typing_extensions import TypeAlias
46

57
from . import dist
@@ -24,9 +26,9 @@ class SetupRequirementsError(BaseException):
2426
def __init__(self, specifiers) -> None: ...
2527

2628
class Distribution(dist.Distribution):
27-
def fetch_build_eggs(self, specifiers) -> None: ...
29+
def fetch_build_eggs(self, specifiers) -> NoReturn: ...
2830
@classmethod
29-
def patch(cls) -> None: ...
31+
def patch(cls) -> _GeneratorContextManager[None]: ...
3032

3133
class _BuildMetaBackend:
3234
def run_setup(self, setup_script: str = "setup.py") -> None: ...

stubs/setuptools/setuptools/command/bdist_egg.pyi

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
from _typeshed import Incomplete, StrPath
2-
from collections.abc import Generator
3-
from typing import ClassVar, Final, TypeVar
1+
from _typeshed import GenericPath, Incomplete, StrPath
2+
from collections.abc import Iterator
3+
from types import CodeType
4+
from typing import AnyStr, ClassVar, Final, TypeVar
45
from zipfile import _ZipFileMode
56

67
from .. import Command
78

89
_StrPathT = TypeVar("_StrPathT", bound=StrPath)
910

1011
def strip_module(filename): ...
11-
def sorted_walk(dir) -> Generator[Incomplete, None, None]: ...
12+
def sorted_walk(dir: GenericPath[AnyStr]) -> Iterator[tuple[AnyStr, list[AnyStr], list[AnyStr]]]: ...
1213
def write_stub(resource, pyfile) -> None: ...
1314

1415
class bdist_egg(Command):
@@ -38,15 +39,15 @@ class bdist_egg(Command):
3839

3940
NATIVE_EXTENSIONS: Final[dict[str, None]]
4041

41-
def walk_egg(egg_dir) -> Generator[Incomplete, None, None]: ...
42+
def walk_egg(egg_dir: StrPath) -> Iterator[tuple[str, list[str], list[str]]]: ...
4243
def analyze_egg(egg_dir, stubs): ...
4344
def write_safety_flag(egg_dir, safe) -> None: ...
4445

4546
safety_flags: Incomplete
4647

4748
def scan_module(egg_dir, base, name, stubs): ...
48-
def iter_symbols(code) -> Generator[Incomplete, None, None]: ...
49-
def can_scan(): ...
49+
def iter_symbols(code: CodeType) -> Iterator[str]: ...
50+
def can_scan() -> bool: ...
5051

5152
INSTALL_DIRECTORY_ATTRS: Final[list[str]]
5253

stubs/setuptools/setuptools/command/build_ext.pyi

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class build_ext(_build_ext):
3030
compiler: Incomplete
3131
def build_extension(self, ext) -> None: ...
3232
def links_to_dynamic(self, ext): ...
33-
def get_outputs(self): ...
33+
def get_source_files(self) -> list[str]: ...
34+
def get_outputs(self) -> list[str]: ...
3435
def get_output_mapping(self) -> dict[str, str]: ...
3536
def write_stub(self, output_dir, ext, compile: bool = False) -> None: ...
3637

stubs/setuptools/setuptools/command/build_py.pyi

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ class build_py(orig.build_py):
2424
level: Unused = 1,
2525
) -> tuple[_StrPathT | str, bool]: ...
2626
def run(self) -> None: ...
27-
data_files: list[tuple[Incomplete, Incomplete, Incomplete, list[Incomplete]]]
27+
data_files: list[tuple[str, str, str, list[str]]]
2828
def __getattr__(self, attr: str): ...
2929
def build_module(self, module, module_file, package): ...
30-
def get_data_files_without_manifest(self) -> list[tuple[Incomplete, Incomplete, Incomplete, list[Incomplete]]]: ...
31-
def find_data_files(self, package, src_dir): ...
30+
def get_data_files_without_manifest(self) -> list[tuple[str, str, str, list[str]]]: ...
31+
def find_data_files(self, package, src_dir) -> list[str]: ...
3232
def get_outputs(self, include_bytecode: bool = True) -> list[str]: ... # type: ignore[override] # Using a real boolean instead of 0|1
3333
def build_package_data(self) -> None: ...
3434
manifest_files: dict[Incomplete, Incomplete]
3535
def get_output_mapping(self) -> dict[str, str]: ...
3636
def analyze_manifest(self) -> None: ...
3737
def get_data_files(self) -> None: ...
3838
def check_package(self, package, package_dir): ...
39-
packages_checked: dict[Incomplete, Incomplete]
4039
def initialize_options(self) -> None: ...
41-
def get_package_dir(self, package): ...
40+
packages_checked: dict[Incomplete, Incomplete]
41+
def get_package_dir(self, package: str) -> str: ...
4242
def exclude_data_files(self, package, src_dir, files): ...
4343

4444
def assert_relative(path): ...

stubs/setuptools/setuptools/command/easy_install.pyi

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from _typeshed import Incomplete
22
from collections.abc import Iterable, Iterator
3-
from typing import Any, ClassVar, Literal, TypedDict
3+
from typing import Any, ClassVar, Literal, NoReturn, TypedDict
44
from typing_extensions import Self
55

6-
from pkg_resources import Environment
6+
from pkg_resources import Distribution, Environment
77
from setuptools.package_index import PackageIndex
88

99
from .. import Command, SetuptoolsDeprecationWarning
@@ -60,28 +60,28 @@ class easy_install(Command):
6060
def pseudo_tempname(self): ...
6161
def warn_deprecated_options(self) -> None: ...
6262
def check_site_dir(self) -> None: ...
63-
def cant_write_to_target(self) -> None: ...
63+
def cant_write_to_target(self) -> NoReturn: ...
6464
def check_pth_processing(self): ...
6565
def install_egg_scripts(self, dist) -> None: ...
6666
def add_output(self, path) -> None: ...
6767
def not_editable(self, spec) -> None: ...
6868
def check_editable(self, spec) -> None: ...
69-
def easy_install(self, spec, deps: bool = False): ...
70-
def install_item(self, spec, download, tmpdir, deps, install_needed: bool = False): ...
69+
def easy_install(self, spec, deps: bool = False) -> Distribution | None: ...
70+
def install_item(self, spec, download, tmpdir, deps, install_needed: bool = False) -> Distribution | None: ...
7171
def select_scheme(self, name) -> None: ...
7272
def process_distribution(self, requirement, dist, deps: bool = True, *info) -> None: ...
73-
def should_unzip(self, dist): ...
73+
def should_unzip(self, dist) -> bool: ...
7474
def maybe_move(self, spec, dist_filename, setup_base): ...
7575
def install_wrapper_scripts(self, dist) -> None: ...
7676
def install_script(self, dist, script_name, script_text, dev_path: Incomplete | None = None) -> None: ...
7777
def write_script(self, script_name, contents, mode: str = "t", blockers=()) -> None: ...
78-
def install_eggs(self, spec, dist_filename, tmpdir): ...
78+
def install_eggs(self, spec, dist_filename, tmpdir) -> list[Distribution]: ...
7979
def egg_distribution(self, egg_path): ...
8080
def install_egg(self, egg_path, tmpdir): ...
8181
def install_exe(self, dist_filename, tmpdir): ...
82-
def exe_to_egg(self, dist_filename, egg_tmp): ...
82+
def exe_to_egg(self, dist_filename, egg_tmp) -> None: ...
8383
def install_wheel(self, wheel_path, tmpdir): ...
84-
def installation_report(self, req, dist, what: str = "Installed"): ...
84+
def installation_report(self, req, dist, what: str = "Installed") -> str: ...
8585
def report_editable(self, spec, setup_script): ...
8686
def run_setup(self, setup_script, setup_base, args) -> None: ...
8787
def build_and_install(self, setup_script, setup_base): ...

stubs/setuptools/setuptools/command/egg_info.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class egg_info(InfoCommon, Command):
3030
egg_version: Incomplete
3131
def initialize_options(self) -> None: ...
3232
@property
33-
def tag_svn_revision(self) -> None: ...
33+
def tag_svn_revision(self) -> int | None: ...
3434
@tag_svn_revision.setter
3535
def tag_svn_revision(self, value) -> None: ...
3636
def save_version_info(self, filename) -> None: ...

stubs/setuptools/setuptools/command/sdist.pyi

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from _typeshed import Incomplete
2+
from collections.abc import Iterator
23
from typing import ClassVar
34

45
from setuptools.dist import Distribution
56

67
from .._distutils.command import sdist as orig
78

8-
def walk_revctrl(dirname: str = "") -> None: ...
9+
def walk_revctrl(dirname: str = "") -> Iterator[Incomplete]: ...
910

1011
class sdist(orig.sdist):
1112
distribution: Distribution # override distutils.dist.Distribution with setuptools.dist.Distribution

stubs/setuptools/setuptools/command/test.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import ClassVar
1+
from typing import ClassVar, NoReturn
22
from typing_extensions import deprecated
33

44
from .. import Command
@@ -14,4 +14,4 @@ class test(Command):
1414
user_options: ClassVar[list[tuple[str, str, str]]]
1515
def initialize_options(self) -> None: ...
1616
def finalize_options(self) -> None: ...
17-
def run(self) -> None: ...
17+
def run(self) -> NoReturn: ...
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
from _typeshed import Incomplete, StrPath
2-
from collections.abc import Callable
3-
from typing import TypeVar
1+
from .setupcfg import parse_configuration as parse_configuration, read_configuration as read_configuration
42

5-
from setuptools.config.setupcfg import AllCommandOptions, ConfigMetadataHandler, ConfigOptionsHandler
6-
from setuptools.dist import Distribution
7-
8-
Fn = TypeVar("Fn", bound=Callable[..., Incomplete]) # noqa: Y001 # Exists at runtime
93
__all__ = ("parse_configuration", "read_configuration")
10-
11-
def read_configuration(
12-
filepath: StrPath, find_others: bool = False, ignore_option_errors: bool = False
13-
) -> dict[Incomplete, Incomplete]: ...
14-
def parse_configuration(
15-
distribution: Distribution, command_options: AllCommandOptions, ignore_option_errors: bool = False
16-
) -> tuple[ConfigMetadataHandler, ConfigOptionsHandler]: ...

stubs/setuptools/setuptools/config/expand.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class EnsurePackagesDiscovered:
4141
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
4242
) -> None: ...
4343
@property
44-
def package_dir(self) -> Mapping[str, str]: ...
44+
def package_dir(self) -> LazyMappingProxy[str, str]: ...
4545

4646
class LazyMappingProxy(Mapping[_K, _V_co]):
4747
def __init__(self, obtain_mapping_value: Callable[[], Mapping[_K, _V_co]]) -> None: ...

stubs/setuptools/setuptools/config/setupcfg.pyi

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from _typeshed import Incomplete, StrPath
2-
from collections.abc import Iterable
2+
from abc import abstractmethod
3+
from collections.abc import Callable, Iterable
34
from typing import Any, ClassVar, Generic, TypeVar
45
from typing_extensions import TypeAlias
56

@@ -38,7 +39,8 @@ class ConfigHandler(Generic[Target]):
3839
ensure_discovered: expand.EnsurePackagesDiscovered,
3940
) -> None: ...
4041
@property
41-
def parsers(self) -> None: ...
42+
@abstractmethod
43+
def parsers(self) -> dict[str, Callable[..., Incomplete]]: ...
4244
def __setitem__(self, option_name, value): ...
4345
def parse_section(self, section_options) -> None: ...
4446
def parse(self) -> None: ...
@@ -59,7 +61,7 @@ class ConfigMetadataHandler(ConfigHandler[DistributionMetadata]):
5961
root_dir: StrPath | None = ".",
6062
) -> None: ...
6163
@property
62-
def parsers(self): ...
64+
def parsers(self) -> dict[str, Callable[..., Incomplete]]: ...
6365

6466
class ConfigOptionsHandler(ConfigHandler[Distribution]):
6567
section_prefix: str
@@ -73,10 +75,10 @@ class ConfigOptionsHandler(ConfigHandler[Distribution]):
7375
ensure_discovered: expand.EnsurePackagesDiscovered,
7476
) -> None: ...
7577
@property
76-
def parsers(self): ...
78+
def parsers(self) -> dict[str, Callable[..., Incomplete]]: ...
7779
def parse_section_packages__find(self, section_options): ...
7880
def parse_section_entry_points(self, section_options) -> None: ...
7981
def parse_section_package_data(self, section_options) -> None: ...
8082
def parse_section_exclude_package_data(self, section_options) -> None: ...
81-
def parse_section_extras_require(self, section_options): ...
83+
def parse_section_extras_require(self, section_options) -> None: ...
8284
def parse_section_data_files(self, section_options) -> None: ...

stubs/setuptools/setuptools/depends.pyi

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from _typeshed import Incomplete
2-
from typing import IO, Any, Literal
2+
from typing import IO, Any, Literal, TypeVar
3+
4+
_T = TypeVar("_T")
35

46
__all__ = ["Require", "find_module", "get_module_constant", "extract_constant"]
57

@@ -19,9 +21,11 @@ class Require:
1921
) -> None: ...
2022
def full_name(self): ...
2123
def version_ok(self, version): ...
22-
def get_version(self, paths: Incomplete | None = None, default: str = "unknown"): ...
24+
def get_version(
25+
self, paths: Incomplete | None = None, default: _T | Literal["unknown"] = "unknown"
26+
) -> _T | Literal["unknown"] | None | Any: ...
2327
def is_present(self, paths: Incomplete | None = None): ...
2428
def is_current(self, paths: Incomplete | None = None): ...
2529

26-
def get_module_constant(module, symbol, default: str | int = -1, paths: Incomplete | None = None) -> Any: ...
27-
def extract_constant(code, symbol, default: str | int = -1) -> Any: ...
30+
def get_module_constant(module, symbol, default: _T | int = -1, paths: Incomplete | None = None) -> _T | int | None | Any: ...
31+
def extract_constant(code, symbol, default: _T | int = -1) -> _T | int | None | Any: ...

stubs/setuptools/setuptools/dist.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class Distribution(_Distribution):
187187
def reinitialize_command(self, command: _CommandT, reinit_subcommands: bool = False) -> _CommandT: ...
188188
def include(self, **attrs) -> None: ...
189189
def exclude_package(self, package: str) -> None: ...
190-
def has_contents_for(self, package: str) -> bool | None: ...
190+
def has_contents_for(self, package: str) -> bool: ...
191191
def exclude(self, **attrs) -> None: ...
192192
def get_cmdline_options(self) -> dict[str, dict[str, str | None]]: ...
193193
def iter_distribution_names(self) -> Iterator[str]: ...

stubs/setuptools/setuptools/msvc.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class RegistryInfo:
5959
def microsoft(self, key: LiteralString, x86: bool = False) -> LiteralString: ...
6060
@overload
6161
def microsoft(self, key: str, x86: bool = False) -> str: ... # type: ignore[misc]
62-
def lookup(self, key: str, name: str) -> str: ...
62+
def lookup(self, key: str, name: str) -> str | None: ...
6363

6464
class SystemInfo:
6565
WinDir: Final[str]
@@ -80,7 +80,7 @@ class SystemInfo:
8080
@property
8181
def VCInstallDir(self) -> str: ...
8282
@property
83-
def WindowsSdkVersion(self) -> tuple[str, ...] | None: ...
83+
def WindowsSdkVersion(self) -> tuple[LiteralString, ...] | None: ...
8484
@property
8585
def WindowsSdkLastVersion(self) -> str: ...
8686
@property
@@ -94,7 +94,7 @@ class SystemInfo:
9494
@property
9595
def UniversalCRTSdkLastVersion(self) -> str: ...
9696
@property
97-
def NetFxSdkVersion(self) -> tuple[str, ...]: ...
97+
def NetFxSdkVersion(self) -> tuple[LiteralString, ...]: ...
9898
@property
9999
def NetFxSdkDir(self) -> str: ...
100100
@property

stubs/setuptools/setuptools/package_index.pyi

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import configparser
22
import urllib.request
33
from _typeshed import Incomplete
4+
from collections.abc import Generator
45
from hashlib import _Hash
56
from re import Pattern
67
from typing import ClassVar
78
from typing_extensions import NamedTuple
89

9-
from pkg_resources import Environment
10+
from pkg_resources import Distribution, Environment
1011

1112
__all__ = ["PackageIndex", "distros_for_url", "parse_bdist_wininst", "interpret_distro_name"]
1213

1314
def parse_bdist_wininst(name): ...
14-
def distros_for_url(url, metadata: Incomplete | None = None) -> None: ...
15+
def distros_for_url(url, metadata: Incomplete | None = None) -> Generator[Distribution]: ...
16+
def distros_for_location(
17+
location, basename, metadata: Incomplete | None = None
18+
) -> list[Distribution] | Generator[Distribution]: ...
1519
def interpret_distro_name(
1620
location, basename, metadata, py_version: Incomplete | None = None, precedence=1, platform: Incomplete | None = None
17-
) -> None: ...
21+
) -> Generator[Distribution]: ...
1822

1923
class ContentChecker:
2024
def feed(self, block) -> None: ...

stubs/setuptools/setuptools/sandbox.pyi

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from types import TracebackType
3-
from typing import ClassVar, Literal
3+
from typing import ClassVar
44
from typing_extensions import Self
55

66
from ._distutils.errors import DistutilsError
@@ -13,9 +13,7 @@ class UnpickleableException(Exception):
1313

1414
class ExceptionSaver:
1515
def __enter__(self) -> Self: ...
16-
def __exit__(
17-
self, type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None
18-
) -> Literal[True] | None: ...
16+
def __exit__(self, type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> bool: ...
1917
def resume(self) -> None: ...
2018

2119
def run_setup(setup_script, args): ...

0 commit comments

Comments
 (0)