Skip to content

Commit 2d990ee

Browse files
henryiiiAlexWaygoodJelleZijlstra
authored
Fill out more annotations for distutils & setuptools dist (#9895)
Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent 629f12e commit 2d990ee

File tree

5 files changed

+126
-57
lines changed

5 files changed

+126
-57
lines changed

stdlib/distutils/dist.pyi

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ from _typeshed import FileDescriptorOrPath, Incomplete, SupportsWrite
22
from collections.abc import Iterable, Mapping
33
from distutils.cmd import Command
44
from re import Pattern
5-
from typing import IO, Any
5+
from typing import IO, Any, ClassVar, TypeVar, overload
6+
from typing_extensions import TypeAlias
67

78
command_re: Pattern[str]
89

10+
_OptionsList: TypeAlias = list[tuple[str, str | None, str, int] | tuple[str, str | None, str]]
11+
_CommandT = TypeVar("_CommandT", bound=Command)
12+
913
class DistributionMetadata:
1014
def __init__(self, path: FileDescriptorOrPath | None = None) -> None: ...
1115
name: str | None
@@ -59,22 +63,22 @@ class Distribution:
5963
def __init__(self, attrs: Mapping[str, Any] | None = None) -> None: ...
6064
def get_option_dict(self, command: str) -> dict[str, tuple[str, str]]: ...
6165
def parse_config_files(self, filenames: Iterable[str] | None = None) -> None: ...
62-
def get_command_obj(self, command: str, create: bool = ...) -> Command | None: ...
63-
global_options: Incomplete
64-
common_usage: str
65-
display_options: Incomplete
66-
display_option_names: Incomplete
67-
negative_opt: Incomplete
66+
def get_command_obj(self, command: str, create: bool = True) -> Command | None: ...
67+
global_options: ClassVar[_OptionsList]
68+
common_usage: ClassVar[str]
69+
display_options: ClassVar[_OptionsList]
70+
display_option_names: ClassVar[list[str]]
71+
negative_opt: ClassVar[dict[str, str]]
6872
verbose: int
6973
dry_run: int
7074
help: int
71-
command_packages: Incomplete
72-
script_name: Incomplete
73-
script_args: Incomplete
74-
command_options: Incomplete
75-
dist_files: Incomplete
75+
command_packages: list[str] | None
76+
script_name: str | None
77+
script_args: list[str] | None
78+
command_options: dict[str, dict[str, tuple[str, str]]]
79+
dist_files: list[tuple[str, str, str]]
7680
packages: Incomplete
77-
package_data: Incomplete
81+
package_data: dict[str, list[str]]
7882
package_dir: Incomplete
7983
py_modules: Incomplete
8084
libraries: Incomplete
@@ -101,21 +105,24 @@ class Distribution:
101105
def print_commands(self) -> None: ...
102106
def get_command_list(self): ...
103107
def get_command_packages(self): ...
104-
def get_command_class(self, command): ...
105-
def reinitialize_command(self, command, reinit_subcommands: int = 0): ...
108+
def get_command_class(self, command: str) -> type[Command]: ...
109+
@overload
110+
def reinitialize_command(self, command: str, reinit_subcommands: bool = False) -> Command: ...
111+
@overload
112+
def reinitialize_command(self, command: _CommandT, reinit_subcommands: bool = False) -> _CommandT: ...
106113
def announce(self, msg, level: int = ...) -> None: ...
107114
def run_commands(self) -> None: ...
108-
def run_command(self, command) -> None: ...
109-
def has_pure_modules(self): ...
110-
def has_ext_modules(self): ...
111-
def has_c_libraries(self): ...
112-
def has_modules(self): ...
113-
def has_headers(self): ...
114-
def has_scripts(self): ...
115-
def has_data_files(self): ...
116-
def is_pure(self): ...
115+
def run_command(self, command: str) -> None: ...
116+
def has_pure_modules(self) -> bool: ...
117+
def has_ext_modules(self) -> bool: ...
118+
def has_c_libraries(self) -> bool: ...
119+
def has_modules(self) -> bool: ...
120+
def has_headers(self) -> bool: ...
121+
def has_scripts(self) -> bool: ...
122+
def has_data_files(self) -> bool: ...
123+
def is_pure(self) -> bool: ...
117124

118-
# Autogenerated getters
125+
# Getter methods generated in __init__
119126
def get_name(self) -> str: ...
120127
def get_version(self) -> str: ...
121128
def get_fullname(self) -> str: ...

stubs/setuptools/@tests/stubtest_allowlist.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ pkg_resources.to_filename
2727
pkg_resources.PathMetadata.egg_info
2828
pkg_resources.EggMetadata.loader
2929

30-
# Dynamically created
30+
# 1 used for True as a default value
31+
setuptools._distutils.dist.Distribution.get_command_obj
32+
33+
# Dynamically created in __init__
3134
setuptools._distutils.dist.Distribution.get_.*
3235

3336
# Uncomment once ignore_missing_stub is turned off

stubs/setuptools/setuptools/_distutils/dist.pyi

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
from _typeshed import FileDescriptorOrPath, Incomplete, SupportsWrite
22
from collections.abc import Iterable, Mapping
3-
from typing import IO
3+
from re import Pattern
4+
from typing import IO, Any, ClassVar, TypeVar, overload
5+
from typing_extensions import TypeAlias
46

57
from .cmd import Command
68

9+
command_re: Pattern[str]
10+
11+
_OptionsList: TypeAlias = list[tuple[str, str | None, str, int] | tuple[str, str | None, str]]
12+
_CommandT = TypeVar("_CommandT", bound=Command)
13+
714
class DistributionMetadata:
8-
def __init__(self, path: FileDescriptorOrPath | None = ...) -> None: ...
15+
def __init__(self, path: FileDescriptorOrPath | None = None) -> None: ...
916
name: str | None
1017
version: str | None
1118
author: str | None
@@ -54,12 +61,69 @@ class DistributionMetadata:
5461
class Distribution:
5562
cmdclass: dict[str, type[Command]]
5663
metadata: DistributionMetadata
57-
def __init__(self, attrs: Mapping[str, Incomplete] | None = ...) -> None: ...
64+
def __init__(self, attrs: Mapping[str, Any] | None = None) -> None: ...
5865
def get_option_dict(self, command: str) -> dict[str, tuple[str, str]]: ...
59-
def parse_config_files(self, filenames: Iterable[str] | None = ...) -> None: ...
60-
def get_command_obj(self, command: str, create: bool = ...) -> Command | None: ...
66+
def parse_config_files(self, filenames: Iterable[str] | None = None) -> None: ...
67+
def get_command_obj(self, command: str, create: bool = True) -> Command | None: ...
68+
global_options: ClassVar[_OptionsList]
69+
common_usage: ClassVar[str]
70+
display_options: ClassVar[_OptionsList]
71+
display_option_names: ClassVar[list[str]]
72+
negative_opt: ClassVar[dict[str, str]]
73+
verbose: int
74+
dry_run: int
75+
help: int
76+
command_packages: list[str] | None
77+
script_name: str | None
78+
script_args: list[str] | None
79+
command_options: dict[str, dict[str, tuple[str, str]]]
80+
dist_files: list[tuple[str, str, str]]
81+
packages: Incomplete
82+
package_data: dict[str, list[str]]
83+
package_dir: Incomplete
84+
py_modules: Incomplete
85+
libraries: Incomplete
86+
headers: Incomplete
87+
ext_modules: Incomplete
88+
ext_package: Incomplete
89+
include_dirs: Incomplete
90+
extra_path: Incomplete
91+
scripts: Incomplete
92+
data_files: Incomplete
93+
password: str
94+
command_obj: dict[str, Command]
95+
have_run: dict[str, bool]
96+
want_user_cfg: bool
97+
def dump_option_dicts(
98+
self, header: Incomplete | None = None, commands: Incomplete | None = None, indent: str = ""
99+
) -> None: ...
100+
def find_config_files(self): ...
101+
commands: Incomplete
102+
def parse_command_line(self): ...
103+
def finalize_options(self) -> None: ...
104+
def handle_display_options(self, option_order): ...
105+
def print_command_list(self, commands, header, max_length) -> None: ...
106+
def print_commands(self) -> None: ...
107+
def get_command_list(self): ...
108+
def get_command_packages(self): ...
109+
def get_command_class(self, command: str) -> type[Command]: ...
110+
@overload
111+
def reinitialize_command(self, command: str, reinit_subcommands: bool = False) -> Command: ...
112+
@overload
113+
def reinitialize_command(self, command: _CommandT, reinit_subcommands: bool = False) -> _CommandT: ...
114+
def announce(self, msg, level: int = ...) -> None: ...
115+
def run_commands(self) -> None: ...
116+
def run_command(self, command: str) -> None: ...
117+
def has_pure_modules(self) -> bool: ...
118+
def has_ext_modules(self) -> bool: ...
119+
def has_c_libraries(self) -> bool: ...
120+
def has_modules(self) -> bool: ...
121+
def has_headers(self) -> bool: ...
122+
def has_scripts(self) -> bool: ...
123+
def has_data_files(self) -> bool: ...
124+
def is_pure(self) -> bool: ...
61125

62-
# Autogenerated getters
126+
# Getter methods generated in __init__
63127
def get_name(self) -> str: ...
64128
def get_version(self) -> str: ...
65129
def get_fullname(self) -> str: ...

stubs/setuptools/setuptools/dist.pyi

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,29 @@
1-
from _typeshed import Incomplete
1+
from collections.abc import Iterable, Iterator, Mapping, MutableMapping
2+
from typing import Any
23

3-
from setuptools import SetuptoolsDeprecationWarning
4+
from setuptools import Command, SetuptoolsDeprecationWarning
45

56
from ._distutils.dist import Distribution as _Distribution
67

78
class Distribution(_Distribution):
8-
def patch_missing_pkg_info(self, attrs) -> None: ...
9-
package_data: Incomplete
10-
dist_files: Incomplete
11-
src_root: Incomplete
12-
dependency_links: Incomplete
13-
setup_requires: Incomplete
14-
def __init__(self, attrs: Incomplete | None = ...) -> None: ...
15-
def warn_dash_deprecation(self, opt, section): ...
16-
def make_option_lowercase(self, opt, section): ...
17-
def parse_config_files(self, filenames: Incomplete | None = ..., ignore_option_errors: bool = ...) -> None: ...
18-
def fetch_build_eggs(self, requires): ...
19-
def finalize_options(self): ...
20-
def get_egg_cache_dir(self): ...
9+
def patch_missing_pkg_info(self, attrs: Mapping[str, Any]) -> None: ...
10+
src_root: str | None
11+
dependency_links: list[str]
12+
setup_requires: list[str]
13+
def __init__(self, attrs: MutableMapping[str, Any] | None = None) -> None: ...
14+
def warn_dash_deprecation(self, opt: str, section: str) -> str: ...
15+
def make_option_lowercase(self, opt: str, section: str) -> str: ...
16+
def parse_config_files(self, filenames: Iterable[str] | None = ..., ignore_option_errors: bool = ...) -> None: ...
17+
def fetch_build_eggs(self, requires: str | Iterable[str]): ...
18+
def get_egg_cache_dir(self) -> str: ...
2119
def fetch_build_egg(self, req): ...
22-
def get_command_class(self, command): ...
23-
def print_commands(self): ...
24-
def get_command_list(self): ...
20+
def get_command_class(self, command: str) -> type[Command]: ...
2521
def include(self, **attrs) -> None: ...
26-
packages: Incomplete
27-
py_modules: Incomplete
28-
ext_modules: Incomplete
29-
def exclude_package(self, package) -> None: ...
30-
def has_contents_for(self, package): ...
22+
def exclude_package(self, package: str) -> None: ...
23+
def has_contents_for(self, package: str) -> bool | None: ...
3124
def exclude(self, **attrs) -> None: ...
32-
def get_cmdline_options(self): ...
33-
def iter_distribution_names(self) -> None: ...
25+
def get_cmdline_options(self) -> dict[str, dict[str, str | None]]: ...
26+
def iter_distribution_names(self) -> Iterator[str]: ...
3427
def handle_display_options(self, option_order): ...
3528

3629
class DistDeprecationWarning(SetuptoolsDeprecationWarning): ...

tests/stubtest_allowlists/py3_common.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ ctypes.memmove # CFunctionType
8484
ctypes.memset # CFunctionType
8585
ctypes.string_at # docstring argument name is wrong
8686
ctypes.wstring_at # docstring argument name is wrong
87+
distutils.core.Distribution.get_command_obj # 1 used for True
8788
distutils.command.bdist_packager # It exists in docs as package name but not in code except as a mention in a comment.
89+
distutils.dist.Distribution.get_command_obj # 1 used for True
8890
distutils.version.Version._cmp # class should have declared this
8991
distutils.version.Version.parse # class should have declared this
9092
enum.Enum._generate_next_value_

0 commit comments

Comments
 (0)