Skip to content

Commit ef42f3b

Browse files
authored
distutils: Type execute using TypeVarTuple (#12405)
1 parent ce9f32d commit ef42f3b

File tree

6 files changed

+43
-19
lines changed

6 files changed

+43
-19
lines changed

stdlib/distutils/ccompiler.pyi

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
from _typeshed import BytesPath, StrPath
1+
from _typeshed import BytesPath, StrPath, Unused
22
from collections.abc import Callable, Iterable
33
from distutils.file_util import _BytesPathT, _StrPathT
4-
from typing import Any, Literal, overload
5-
from typing_extensions import TypeAlias
4+
from typing import Literal, overload
5+
from typing_extensions import TypeAlias, TypeVarTuple, Unpack
66

77
_Macro: TypeAlias = tuple[str] | tuple[str, str | None]
8+
_Ts = TypeVarTuple("_Ts")
89

910
def gen_lib_options(
1011
compiler: CCompiler, library_dirs: list[str], runtime_library_dirs: list[str], libraries: list[str]
@@ -161,7 +162,9 @@ class CCompiler:
161162
def shared_object_filename(self, basename: str, strip_dir: Literal[0, False] = 0, output_dir: StrPath = "") -> str: ...
162163
@overload
163164
def shared_object_filename(self, basename: StrPath, strip_dir: Literal[1, True], output_dir: StrPath = "") -> str: ...
164-
def execute(self, func: Callable[..., object], args: tuple[Any, ...], msg: str | None = None, level: int = 1) -> None: ...
165+
def execute(
166+
self, func: Callable[[Unpack[_Ts]], Unused], args: tuple[Unpack[_Ts]], msg: str | None = None, level: int = 1
167+
) -> None: ...
165168
def spawn(self, cmd: list[str]) -> None: ...
166169
def mkpath(self, name: str, mode: int = 0o777) -> None: ...
167170
@overload

stdlib/distutils/cmd.pyi

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ from collections.abc import Callable, Iterable
44
from distutils.dist import Distribution
55
from distutils.file_util import _BytesPathT, _StrPathT
66
from typing import Any, ClassVar, Literal, overload
7+
from typing_extensions import TypeVarTuple, Unpack
8+
9+
_Ts = TypeVarTuple("_Ts")
710

811
class Command:
912
distribution: Distribution
@@ -29,7 +32,9 @@ class Command:
2932
def run_command(self, command: str) -> None: ...
3033
def get_sub_commands(self) -> list[str]: ...
3134
def warn(self, msg: str) -> None: ...
32-
def execute(self, func: Callable[..., object], args: Iterable[Any], msg: str | None = None, level: int = 1) -> None: ...
35+
def execute(
36+
self, func: Callable[[Unpack[_Ts]], Unused], args: tuple[Unpack[_Ts]], msg: str | None = None, level: int = 1
37+
) -> None: ...
3338
def mkpath(self, name: str, mode: int = 0o777) -> None: ...
3439
@overload
3540
def copy_file(
@@ -89,8 +94,8 @@ class Command:
8994
self,
9095
infiles: str | list[str] | tuple[str, ...],
9196
outfile: StrOrBytesPath,
92-
func: Callable[..., object],
93-
args: list[Any],
97+
func: Callable[[Unpack[_Ts]], Unused],
98+
args: tuple[Unpack[_Ts]],
9499
exec_msg: str | None = None,
95100
skip_msg: str | None = None,
96101
level: Unused = 1,

stdlib/distutils/util.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from _typeshed import StrPath, Unused
22
from collections.abc import Callable, Container, Iterable, Mapping
33
from typing import Any, Literal
4+
from typing_extensions import TypeVarTuple, Unpack
5+
6+
_Ts = TypeVarTuple("_Ts")
47

58
def get_host_platform() -> str: ...
69
def get_platform() -> str: ...
@@ -10,8 +13,8 @@ def check_environ() -> None: ...
1013
def subst_vars(s: str, local_vars: Mapping[str, str]) -> None: ...
1114
def split_quoted(s: str) -> list[str]: ...
1215
def execute(
13-
func: Callable[..., object],
14-
args: tuple[Any, ...],
16+
func: Callable[[Unpack[_Ts]], Unused],
17+
args: tuple[Unpack[_Ts]],
1518
msg: str | None = None,
1619
verbose: bool | Literal[0, 1] = 0,
1720
dry_run: bool | Literal[0, 1] = 0,

stubs/setuptools/setuptools/_distutils/ccompiler.pyi

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
from _typeshed import BytesPath, StrPath
1+
from _typeshed import BytesPath, StrPath, Unused
22
from collections.abc import Callable, Iterable
3-
from typing import Any, ClassVar, Literal, TypeVar, overload
4-
from typing_extensions import TypeAlias
3+
from typing import ClassVar, Literal, TypeVar, overload
4+
from typing_extensions import TypeAlias, TypeVarTuple, Unpack
55

66
_Macro: TypeAlias = tuple[str] | tuple[str, str | None]
77
_StrPathT = TypeVar("_StrPathT", bound=StrPath)
88
_BytesPathT = TypeVar("_BytesPathT", bound=BytesPath)
9+
_Ts = TypeVarTuple("_Ts")
910

1011
def gen_lib_options(
1112
compiler: CCompiler, library_dirs: list[str], runtime_library_dirs: list[str], libraries: list[str]
@@ -165,7 +166,9 @@ class CCompiler:
165166
def shared_object_filename(self, basename: str, strip_dir: Literal[0, False] = 0, output_dir: StrPath = ...) -> str: ...
166167
@overload
167168
def shared_object_filename(self, basename: StrPath, strip_dir: Literal[1, True], output_dir: StrPath = ...) -> str: ...
168-
def execute(self, func: Callable[..., object], args: tuple[Any, ...], msg: str | None = ..., level: int = ...) -> None: ...
169+
def execute(
170+
self, func: Callable[[Unpack[_Ts]], Unused], args: tuple[Unpack[_Ts]], msg: str | None = ..., level: int = ...
171+
) -> None: ...
169172
def spawn(self, cmd: list[str]) -> None: ...
170173
def mkpath(self, name: str, mode: int = ...) -> None: ...
171174
@overload

stubs/setuptools/setuptools/_distutils/cmd.pyi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
from _typeshed import BytesPath, Incomplete, StrOrBytesPath, StrPath, Unused
1+
from _typeshed import BytesPath, StrOrBytesPath, StrPath, Unused
22
from abc import abstractmethod
33
from collections.abc import Callable, Iterable
44
from typing import Any, ClassVar, TypeVar, overload
5+
from typing_extensions import TypeVarTuple, Unpack
56

67
from .dist import Distribution
78

89
_StrPathT = TypeVar("_StrPathT", bound=StrPath)
910
_BytesPathT = TypeVar("_BytesPathT", bound=BytesPath)
11+
_Ts = TypeVarTuple("_Ts")
1012

1113
class Command:
1214
distribution: Distribution
@@ -34,7 +36,7 @@ class Command:
3436
def get_sub_commands(self) -> list[str]: ...
3537
def warn(self, msg: str) -> None: ...
3638
def execute(
37-
self, func: Callable[..., object], args: Iterable[Incomplete], msg: str | None = ..., level: int = ...
39+
self, func: Callable[[Unpack[_Ts]], Unused], args: tuple[Unpack[_Ts]], msg: str | None = ..., level: int = ...
3840
) -> None: ...
3941
def mkpath(self, name: str, mode: int = ...) -> None: ...
4042
@overload
@@ -95,8 +97,8 @@ class Command:
9597
self,
9698
infiles: str | list[str] | tuple[str, ...],
9799
outfile: StrOrBytesPath,
98-
func: Callable[..., object],
99-
args: list[Incomplete],
100+
func: Callable[[Unpack[_Ts]], Unused],
101+
args: tuple[Unpack[_Ts]],
100102
exec_msg: str | None = None,
101103
skip_msg: str | None = None,
102104
level: Unused = 1,

stubs/setuptools/setuptools/_distutils/util.pyi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
from _typeshed import Unused
12
from collections.abc import Callable, Mapping
2-
from typing import Any, Literal
3+
from typing import Literal
4+
from typing_extensions import TypeVarTuple, Unpack
5+
6+
_Ts = TypeVarTuple("_Ts")
37

48
def get_host_platform() -> str: ...
59
def get_platform() -> str: ...
@@ -13,7 +17,11 @@ def subst_vars(s: str, local_vars: Mapping[str, str]) -> None: ...
1317
def grok_environment_error(exc: object, prefix: str = ...) -> str: ...
1418
def split_quoted(s: str) -> list[str]: ...
1519
def execute(
16-
func: Callable[..., object], args: tuple[Any, ...], msg: str | None = ..., verbose: bool = False, dry_run: bool = False
20+
func: Callable[[Unpack[_Ts]], Unused],
21+
args: tuple[Unpack[_Ts]],
22+
msg: str | None = ...,
23+
verbose: bool = False,
24+
dry_run: bool = False,
1725
) -> None: ...
1826
def strtobool(val: str) -> Literal[0, 1]: ...
1927
def byte_compile(

0 commit comments

Comments
 (0)