Debian Codegraph @

jedi/third_party/typeshed/stdlib/shutil.pyi

raw symbols SCIP
1 import os
2 import sys
3 from _typeshed import BytesPath, ExcInfo, FileDescriptorOrPath, MaybeNone, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite
4 from collections.abc import Callable, Iterable, Sequence
5 from tarfile import _TarfileFilter
6 from typing import Any, AnyStr, NamedTuple, NoReturn, Protocol, TypeVar, overload, type_check_only
7 from typing_extensions import TypeAlias, deprecated
8
9 __all__ = [
10 "copyfileobj",
11 "copyfile",
12 "copymode",
13 "copystat",
14 "copy",
15 "copy2",
16 "copytree",
17 "move",
18 "rmtree",
19 "Error",
20 "SpecialFileError",
21 "make_archive",
22 "get_archive_formats",
23 "register_archive_format",
24 "unregister_archive_format",
25 "get_unpack_formats",
26 "register_unpack_format",
27 "unregister_unpack_format",
28 "unpack_archive",
29 "ignore_patterns",
30 "chown",
31 "which",
32 "get_terminal_size",
33 "SameFileError",
34 "disk_usage",
35 ]
36 if sys.version_info < (3, 14):
37 __all__ += ["ExecError"]
38
39 _StrOrBytesPathT = TypeVar("_StrOrBytesPathT", bound=StrOrBytesPath)
40 _StrPathT = TypeVar("_StrPathT", bound=StrPath)
41 _BytesPathT = TypeVar("_BytesPathT", bound=BytesPath)
42
43 class Error(OSError): ...
44 class SameFileError(Error): ...
45 class SpecialFileError(OSError): ...
46
47 if sys.version_info >= (3, 14):
48 ExecError = RuntimeError # Deprecated in Python 3.14; removal scheduled for Python 3.16
49
50 else:
51 class ExecError(OSError): ...
52
53 class ReadError(OSError): ...
54 class RegistryError(Exception): ...
55
56 def copyfileobj(fsrc: SupportsRead[AnyStr], fdst: SupportsWrite[AnyStr], length: int = 0) -> None: ...
57 def copyfile(src: StrOrBytesPath, dst: _StrOrBytesPathT, *, follow_symlinks: bool = True) -> _StrOrBytesPathT: ...
58 def copymode(src: StrOrBytesPath, dst: StrOrBytesPath, *, follow_symlinks: bool = True) -> None: ...
59 def copystat(src: StrOrBytesPath, dst: StrOrBytesPath, *, follow_symlinks: bool = True) -> None: ...
60 @overload
61 def copy(src: StrPath, dst: _StrPathT, *, follow_symlinks: bool = True) -> _StrPathT | str: ...
62 @overload
63 def copy(src: BytesPath, dst: _BytesPathT, *, follow_symlinks: bool = True) -> _BytesPathT | bytes: ...
64 @overload
65 def copy2(src: StrPath, dst: _StrPathT, *, follow_symlinks: bool = True) -> _StrPathT | str: ...
66 @overload
67 def copy2(src: BytesPath, dst: _BytesPathT, *, follow_symlinks: bool = True) -> _BytesPathT | bytes: ...
68 def ignore_patterns(*patterns: StrPath) -> Callable[[Any, list[str]], set[str]]: ...
69 def copytree(
70 src: StrPath,
71 dst: _StrPathT,
72 symlinks: bool = False,
73 ignore: None | Callable[[str, list[str]], Iterable[str]] | Callable[[StrPath, list[str]], Iterable[str]] = None,
74 copy_function: Callable[[str, str], object] = ...,
75 ignore_dangling_symlinks: bool = False,
76 dirs_exist_ok: bool = False,
77 ) -> _StrPathT: ...
78
79 _OnErrorCallback: TypeAlias = Callable[[Callable[..., Any], str, ExcInfo], object]
80 _OnExcCallback: TypeAlias = Callable[[Callable[..., Any], str, BaseException], object]
81
82 @type_check_only
83 class _RmtreeType(Protocol):
84 avoids_symlink_attacks: bool
85 if sys.version_info >= (3, 12):
86 @overload
87 @deprecated("The `onerror` parameter is deprecated. Use `onexc` instead.")
88 def __call__(
89 self,
90 path: StrOrBytesPath,
91 ignore_errors: bool,
92 onerror: _OnErrorCallback | None,
93 *,
94 onexc: None = None,
95 dir_fd: int | None = None,
96 ) -> None: ...
97 @overload
98 @deprecated("The `onerror` parameter is deprecated. Use `onexc` instead.")
99 def __call__(
100 self,
101 path: StrOrBytesPath,
102 ignore_errors: bool = False,
103 *,
104 onerror: _OnErrorCallback | None,
105 onexc: None = None,
106 dir_fd: int | None = None,
107 ) -> None: ...
108 @overload
109 def __call__(
110 self,
111 path: StrOrBytesPath,
112 ignore_errors: bool = False,
113 *,
114 onexc: _OnExcCallback | None = None,
115 dir_fd: int | None = None,
116 ) -> None: ...
117 elif sys.version_info >= (3, 11):
118 def __call__(
119 self,
120 path: StrOrBytesPath,
121 ignore_errors: bool = False,
122 onerror: _OnErrorCallback | None = None,
123 *,
124 dir_fd: int | None = None,
125 ) -> None: ...
126
127 else:
128 def __call__(
129 self, path: StrOrBytesPath, ignore_errors: bool = False, onerror: _OnErrorCallback | None = None
130 ) -> None: ...
131
132 rmtree: _RmtreeType
133
134 _CopyFn: TypeAlias = Callable[[str, str], object] | Callable[[StrPath, StrPath], object]
135
136 # N.B. shutil.move appears to take bytes arguments, however,
137 # this does not work when dst is (or is within) an existing directory.
138 # (#6832)
139 def move(src: StrPath, dst: _StrPathT, copy_function: _CopyFn = ...) -> _StrPathT | str | MaybeNone: ...
140
141 class _ntuple_diskusage(NamedTuple):
142 total: int
143 used: int
144 free: int
145
146 def disk_usage(path: FileDescriptorOrPath) -> _ntuple_diskusage: ...
147
148 # While chown can be imported on Windows, it doesn't actually work;
149 # see https://bugs.python.org/issue33140. We keep it here because it's
150 # in __all__.
151 if sys.version_info >= (3, 13):
152 @overload
153 def chown(
154 path: FileDescriptorOrPath,
155 user: str | int,
156 group: None = None,
157 *,
158 dir_fd: int | None = None,
159 follow_symlinks: bool = True,
160 ) -> None: ...
161 @overload
162 def chown(
163 path: FileDescriptorOrPath,
164 user: None = None,
165 *,
166 group: str | int,
167 dir_fd: int | None = None,
168 follow_symlinks: bool = True,
169 ) -> None: ...
170 @overload
171 def chown(
172 path: FileDescriptorOrPath, user: None, group: str | int, *, dir_fd: int | None = None, follow_symlinks: bool = True
173 ) -> None: ...
174 @overload
175 def chown(
176 path: FileDescriptorOrPath, user: str | int, group: str | int, *, dir_fd: int | None = None, follow_symlinks: bool = True
177 ) -> None: ...
178
179 else:
180 @overload
181 def chown(path: FileDescriptorOrPath, user: str | int, group: None = None) -> None: ...
182 @overload
183 def chown(path: FileDescriptorOrPath, user: None = None, *, group: str | int) -> None: ...
184 @overload
185 def chown(path: FileDescriptorOrPath, user: None, group: str | int) -> None: ...
186 @overload
187 def chown(path: FileDescriptorOrPath, user: str | int, group: str | int) -> None: ...
188
189 if sys.platform == "win32" and sys.version_info < (3, 12):
190 @overload
191 @deprecated("On Windows before Python 3.12, using a PathLike as `cmd` would always fail or return `None`.")
192 def which(cmd: os.PathLike[str], mode: int = 1, path: StrPath | None = None) -> NoReturn: ...
193
194 @overload
195 def which(cmd: StrPath, mode: int = 1, path: StrPath | None = None) -> str | None: ...
196 @overload
197 def which(cmd: bytes, mode: int = 1, path: StrPath | None = None) -> bytes | None: ...
198 def make_archive(
199 base_name: str,
200 format: str,
201 root_dir: StrPath | None = None,
202 base_dir: StrPath | None = None,
203 verbose: bool = ...,
204 dry_run: bool = ...,
205 owner: str | None = None,
206 group: str | None = None,
207 logger: Any | None = None,
208 ) -> str: ...
209 def get_archive_formats() -> list[tuple[str, str]]: ...
210 @overload
211 def register_archive_format(
212 name: str, function: Callable[..., object], extra_args: Sequence[tuple[str, Any] | list[Any]], description: str = ""
213 ) -> None: ...
214 @overload
215 def register_archive_format(
216 name: str, function: Callable[[str, str], object], extra_args: None = None, description: str = ""
217 ) -> None: ...
218 def unregister_archive_format(name: str) -> None: ...
219 def unpack_archive(
220 filename: StrPath, extract_dir: StrPath | None = None, format: str | None = None, *, filter: _TarfileFilter | None = None
221 ) -> None: ...
222 @overload
223 def register_unpack_format(
224 name: str,
225 extensions: list[str],
226 function: Callable[..., object],
227 extra_args: Sequence[tuple[str, Any]],
228 description: str = "",
229 ) -> None: ...
230 @overload
231 def register_unpack_format(
232 name: str, extensions: list[str], function: Callable[[str, str], object], extra_args: None = None, description: str = ""
233 ) -> None: ...
234 def unregister_unpack_format(name: str) -> None: ...
235 def get_unpack_formats() -> list[tuple[str, list[str], str]]: ...
236 def get_terminal_size(fallback: tuple[int, int] = (80, 24)) -> os.terminal_size: ...