-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
shutil.pyi
171 lines (153 loc) · 6.12 KB
/
shutil.pyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import os
import sys
from _typeshed import BytesPath, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite
from collections.abc import Callable, Iterable, Sequence
from typing import Any, AnyStr, NamedTuple, TypeVar, overload
from typing_extensions import TypeAlias
__all__ = [
"copyfileobj",
"copyfile",
"copymode",
"copystat",
"copy",
"copy2",
"copytree",
"move",
"rmtree",
"Error",
"SpecialFileError",
"ExecError",
"make_archive",
"get_archive_formats",
"register_archive_format",
"unregister_archive_format",
"get_unpack_formats",
"register_unpack_format",
"unregister_unpack_format",
"unpack_archive",
"ignore_patterns",
"chown",
"which",
"get_terminal_size",
"SameFileError",
"disk_usage",
]
_StrOrBytesPathT = TypeVar("_StrOrBytesPathT", bound=StrOrBytesPath)
_StrPathT = TypeVar("_StrPathT", bound=StrPath)
# Return value of some functions that may either return a path-like object that was passed in or
# a string
_PathReturn: TypeAlias = Any
class Error(OSError): ...
class SameFileError(Error): ...
class SpecialFileError(OSError): ...
class ExecError(OSError): ...
class ReadError(OSError): ...
class RegistryError(Exception): ...
def copyfileobj(fsrc: SupportsRead[AnyStr], fdst: SupportsWrite[AnyStr], length: int = ...) -> None: ...
def copyfile(src: StrOrBytesPath, dst: _StrOrBytesPathT, *, follow_symlinks: bool = ...) -> _StrOrBytesPathT: ...
def copymode(src: StrOrBytesPath, dst: StrOrBytesPath, *, follow_symlinks: bool = ...) -> None: ...
def copystat(src: StrOrBytesPath, dst: StrOrBytesPath, *, follow_symlinks: bool = ...) -> None: ...
@overload
def copy(src: StrPath, dst: StrPath, *, follow_symlinks: bool = ...) -> _PathReturn: ...
@overload
def copy(src: BytesPath, dst: BytesPath, *, follow_symlinks: bool = ...) -> _PathReturn: ...
@overload
def copy2(src: StrPath, dst: StrPath, *, follow_symlinks: bool = ...) -> _PathReturn: ...
@overload
def copy2(src: BytesPath, dst: BytesPath, *, follow_symlinks: bool = ...) -> _PathReturn: ...
def ignore_patterns(*patterns: StrPath) -> Callable[[Any, list[str]], set[str]]: ...
if sys.version_info >= (3, 8):
def copytree(
src: StrPath,
dst: StrPath,
symlinks: bool = ...,
ignore: None | Callable[[str, list[str]], Iterable[str]] | Callable[[StrPath, list[str]], Iterable[str]] = ...,
copy_function: Callable[[str, str], object] = ...,
ignore_dangling_symlinks: bool = ...,
dirs_exist_ok: bool = ...,
) -> _PathReturn: ...
else:
def copytree(
src: StrPath,
dst: StrPath,
symlinks: bool = ...,
ignore: None | Callable[[str, list[str]], Iterable[str]] | Callable[[StrPath, list[str]], Iterable[str]] = ...,
copy_function: Callable[[str, str], object] = ...,
ignore_dangling_symlinks: bool = ...,
) -> _PathReturn: ...
_OnErrorCallback: TypeAlias = Callable[[Callable[..., Any], Any, Any], object]
if sys.version_info >= (3, 11):
def rmtree(
path: StrOrBytesPath, ignore_errors: bool = ..., onerror: _OnErrorCallback | None = ..., *, dir_fd: int | None = ...
) -> None: ...
else:
def rmtree(path: StrOrBytesPath, ignore_errors: bool = ..., onerror: _OnErrorCallback | None = ...) -> None: ...
_CopyFn: TypeAlias = Callable[[str, str], object] | Callable[[StrPath, StrPath], object]
# N.B. shutil.move appears to take bytes arguments, however,
# this does not work when dst is (or is within) an existing directory.
# (#6832)
if sys.version_info >= (3, 9):
def move(src: StrPath, dst: StrPath, copy_function: _CopyFn = ...) -> _PathReturn: ...
else:
# See https://bugs.python.org/issue32689
def move(src: str, dst: StrPath, copy_function: _CopyFn = ...) -> _PathReturn: ...
class _ntuple_diskusage(NamedTuple):
total: int
used: int
free: int
def disk_usage(path: int | StrOrBytesPath) -> _ntuple_diskusage: ...
# While chown can be imported on Windows, it doesn't actually work;
# see https://bugs.python.org/issue33140. We keep it here because it's
# in __all__.
@overload
def chown(path: StrOrBytesPath, user: str | int, group: None = ...) -> None: ...
@overload
def chown(path: StrOrBytesPath, user: None = ..., *, group: str | int) -> None: ...
@overload
def chown(path: StrOrBytesPath, user: None, group: str | int) -> None: ...
@overload
def chown(path: StrOrBytesPath, user: str | int, group: str | int) -> None: ...
if sys.version_info >= (3, 8):
@overload
def which(cmd: _StrPathT, mode: int = ..., path: StrPath | None = ...) -> str | _StrPathT | None: ...
@overload
def which(cmd: bytes, mode: int = ..., path: StrPath | None = ...) -> bytes | None: ...
else:
def which(cmd: _StrPathT, mode: int = ..., path: StrPath | None = ...) -> str | _StrPathT | None: ...
def make_archive(
base_name: str,
format: str,
root_dir: StrPath | None = ...,
base_dir: StrPath | None = ...,
verbose: bool = ...,
dry_run: bool = ...,
owner: str | None = ...,
group: str | None = ...,
logger: Any | None = ...,
) -> str: ...
def get_archive_formats() -> list[tuple[str, str]]: ...
@overload
def register_archive_format(
name: str, function: Callable[..., object], extra_args: Sequence[tuple[str, Any] | list[Any]], description: str = ...
) -> None: ...
@overload
def register_archive_format(
name: str, function: Callable[[str, str], object], extra_args: None = ..., description: str = ...
) -> None: ...
def unregister_archive_format(name: str) -> None: ...
def unpack_archive(filename: StrPath, extract_dir: StrPath | None = ..., format: str | None = ...) -> None: ...
@overload
def register_unpack_format(
name: str,
extensions: list[str],
function: Callable[..., object],
extra_args: Sequence[tuple[str, Any]],
description: str = ...,
) -> None: ...
@overload
def register_unpack_format(
name: str, extensions: list[str], function: Callable[[str, str], object], extra_args: None = ..., description: str = ...
) -> None: ...
def unregister_unpack_format(name: str) -> None: ...
def get_unpack_formats() -> list[tuple[str, list[str], str]]: ...
def get_terminal_size(fallback: tuple[int, int] = ...) -> os.terminal_size: ...