Skip to content

Commit 19e9575

Browse files
committed
Merge typeshed's setuptools._distutils annotations
1 parent 91f75bb commit 19e9575

31 files changed

+936
-482
lines changed

distutils/_modified.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,32 @@
22

33
import functools
44
import os.path
5+
from collections.abc import Callable, Iterable
6+
from typing import Literal, TypeVar
57

68
from jaraco.functools import splat
79

810
from .compat.py39 import zip_strict
911
from .errors import DistutilsFileError
1012

13+
_SourcesT = TypeVar(
14+
"_SourcesT", bound=str | bytes | os.PathLike[str] | os.PathLike[bytes]
15+
)
16+
_TargetsT = TypeVar(
17+
"_TargetsT", bound=str | bytes | os.PathLike[str] | os.PathLike[bytes]
18+
)
19+
1120

1221
def _newer(source, target):
1322
return not os.path.exists(target) or (
1423
os.path.getmtime(source) > os.path.getmtime(target)
1524
)
1625

1726

18-
def newer(source, target):
27+
def newer(
28+
source: str | bytes | os.PathLike[str] | os.PathLike[bytes],
29+
target: str | bytes | os.PathLike[str] | os.PathLike[bytes],
30+
) -> bool:
1931
"""
2032
Is source modified more recently than target.
2133
@@ -25,12 +37,16 @@ def newer(source, target):
2537
Raises DistutilsFileError if 'source' does not exist.
2638
"""
2739
if not os.path.exists(source):
28-
raise DistutilsFileError(f"file '{os.path.abspath(source)}' does not exist")
40+
raise DistutilsFileError(f"file {os.path.abspath(source)!r} does not exist")
2941

3042
return _newer(source, target)
3143

3244

33-
def newer_pairwise(sources, targets, newer=newer):
45+
def newer_pairwise(
46+
sources: Iterable[_SourcesT],
47+
targets: Iterable[_TargetsT],
48+
newer: Callable[[_SourcesT, _TargetsT], bool] = newer,
49+
) -> tuple[list[_SourcesT], list[_TargetsT]]:
3450
"""
3551
Filter filenames where sources are newer than targets.
3652
@@ -43,7 +59,11 @@ def newer_pairwise(sources, targets, newer=newer):
4359
return tuple(map(list, zip(*newer_pairs))) or ([], [])
4460

4561

46-
def newer_group(sources, target, missing='error'):
62+
def newer_group(
63+
sources: Iterable[str | bytes | os.PathLike[str] | os.PathLike[bytes]],
64+
target: str | bytes | os.PathLike[str] | os.PathLike[bytes],
65+
missing: Literal["error", "ignore", "newer"] = "error",
66+
) -> bool:
4767
"""
4868
Is target out-of-date with respect to any file in sources.
4969

distutils/archive_util.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
that sort of thing)."""
55

66
import os
7+
from typing import Literal
78

89
try:
910
import zipfile
@@ -54,14 +55,14 @@ def _get_uid(name):
5455

5556

5657
def make_tarball(
57-
base_name,
58-
base_dir,
59-
compress="gzip",
60-
verbose=False,
61-
dry_run=False,
62-
owner=None,
63-
group=None,
64-
):
58+
base_name: str,
59+
base_dir: str | os.PathLike[str],
60+
compress: Literal["gzip", "bzip2", "xz"] | None = "gzip",
61+
verbose: bool = False,
62+
dry_run: bool = False,
63+
owner: str | None = None,
64+
group: str | None = None,
65+
) -> str:
6566
"""Create a (possibly compressed) tar file from all the files under
6667
'base_dir'.
6768
@@ -122,7 +123,12 @@ def _set_uid_gid(tarinfo):
122123
return archive_name
123124

124125

125-
def make_zipfile(base_name, base_dir, verbose=False, dry_run=False): # noqa: C901
126+
def make_zipfile(
127+
base_name: str,
128+
base_dir: str | os.PathLike[str],
129+
verbose: bool = False,
130+
dry_run: bool = False,
131+
) -> str: # noqa: C901
126132
"""Create a zip file from all the files under 'base_dir'.
127133
128134
The output zip file will be named 'base_name' + ".zip". Uses either the
@@ -205,15 +211,15 @@ def check_archive_formats(formats):
205211

206212

207213
def make_archive(
208-
base_name,
209-
format,
210-
root_dir=None,
211-
base_dir=None,
212-
verbose=False,
213-
dry_run=False,
214-
owner=None,
215-
group=None,
216-
):
214+
base_name: str,
215+
format: str,
216+
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes] | None = None,
217+
base_dir: str | None = None,
218+
verbose: bool = False,
219+
dry_run: bool = False,
220+
owner: str | None = None,
221+
group: str | None = None,
222+
) -> str:
217223
"""Create an archive file (eg. zip or tar).
218224
219225
'base_name' is the name of the file to create, minus any format-specific

0 commit comments

Comments
 (0)