massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / os / __init__.pyi
1 import sys
2 from _typeshed import (
3     FileDescriptorLike,
4     OpenBinaryMode,
5     OpenBinaryModeReading,
6     OpenBinaryModeUpdating,
7     OpenBinaryModeWriting,
8     OpenTextMode,
9     Self,
10     StrOrBytesPath,
11     StrPath,
12 )
13 from builtins import OSError
14 from contextlib import AbstractContextManager
15 from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper as _TextIOWrapper
16 from posix import listdir as listdir, times_result
17 from subprocess import Popen
18 from typing import (
19     IO,
20     Any,
21     AnyStr,
22     BinaryIO,
23     Callable,
24     Generic,
25     Iterable,
26     Iterator,
27     List,
28     Mapping,
29     MutableMapping,
30     NoReturn,
31     Protocol,
32     Sequence,
33     Tuple,
34     TypeVar,
35     Union,
36     overload,
37     runtime_checkable,
38 )
39 from typing_extensions import Literal, final
40
41 from . import path as _path
42
43 if sys.version_info >= (3, 9):
44     from types import GenericAlias
45
46 # This unnecessary alias is to work around various errors
47 path = _path
48
49 _T = TypeVar("_T")
50 _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True)
51
52 # ----- os variables -----
53
54 error = OSError
55
56 supports_bytes_environ: bool
57
58 supports_dir_fd: set[Callable[..., Any]]
59 supports_fd: set[Callable[..., Any]]
60 supports_effective_ids: set[Callable[..., Any]]
61 supports_follow_symlinks: set[Callable[..., Any]]
62
63 if sys.platform != "win32":
64     # Unix only
65     PRIO_PROCESS: int
66     PRIO_PGRP: int
67     PRIO_USER: int
68
69     F_LOCK: int
70     F_TLOCK: int
71     F_ULOCK: int
72     F_TEST: int
73
74     if sys.platform != "darwin":
75         POSIX_FADV_NORMAL: int
76         POSIX_FADV_SEQUENTIAL: int
77         POSIX_FADV_RANDOM: int
78         POSIX_FADV_NOREUSE: int
79         POSIX_FADV_WILLNEED: int
80         POSIX_FADV_DONTNEED: int
81
82     SF_NODISKIO: int
83     SF_MNOWAIT: int
84     SF_SYNC: int
85
86     if sys.platform == "linux":
87         XATTR_SIZE_MAX: int
88         XATTR_CREATE: int
89         XATTR_REPLACE: int
90
91     P_PID: int
92     P_PGID: int
93     P_ALL: int
94
95     WEXITED: int
96     WSTOPPED: int
97     WNOWAIT: int
98
99     CLD_EXITED: int
100     CLD_DUMPED: int
101     CLD_TRAPPED: int
102     CLD_CONTINUED: int
103
104     SCHED_OTHER: int  # some flavors of Unix
105     SCHED_BATCH: int  # some flavors of Unix
106     SCHED_IDLE: int  # some flavors of Unix
107     SCHED_SPORADIC: int  # some flavors of Unix
108     SCHED_FIFO: int  # some flavors of Unix
109     SCHED_RR: int  # some flavors of Unix
110     SCHED_RESET_ON_FORK: int  # some flavors of Unix
111
112 if sys.platform != "win32":
113     RTLD_LAZY: int
114     RTLD_NOW: int
115     RTLD_GLOBAL: int
116     RTLD_LOCAL: int
117     RTLD_NODELETE: int
118     RTLD_NOLOAD: int
119
120 if sys.platform == "linux":
121     RTLD_DEEPBIND: int
122
123 SEEK_SET: int
124 SEEK_CUR: int
125 SEEK_END: int
126 if sys.platform != "win32":
127     SEEK_DATA: int  # some flavors of Unix
128     SEEK_HOLE: int  # some flavors of Unix
129
130 O_RDONLY: int
131 O_WRONLY: int
132 O_RDWR: int
133 O_APPEND: int
134 O_CREAT: int
135 O_EXCL: int
136 O_TRUNC: int
137 # We don't use sys.platform for O_* flags to denote platform-dependent APIs because some codes,
138 # including tests for mypy, use a more finer way than sys.platform before using these APIs
139 # See https://github.com/python/typeshed/pull/2286 for discussions
140 O_DSYNC: int  # Unix only
141 O_RSYNC: int  # Unix only
142 O_SYNC: int  # Unix only
143 O_NDELAY: int  # Unix only
144 O_NONBLOCK: int  # Unix only
145 O_NOCTTY: int  # Unix only
146 O_CLOEXEC: int  # Unix only
147 O_SHLOCK: int  # Unix only
148 O_EXLOCK: int  # Unix only
149 O_BINARY: int  # Windows only
150 O_NOINHERIT: int  # Windows only
151 O_SHORT_LIVED: int  # Windows only
152 O_TEMPORARY: int  # Windows only
153 O_RANDOM: int  # Windows only
154 O_SEQUENTIAL: int  # Windows only
155 O_TEXT: int  # Windows only
156 O_ASYNC: int  # Gnu extension if in C library
157 O_DIRECT: int  # Gnu extension if in C library
158 O_DIRECTORY: int  # Gnu extension if in C library
159 O_NOFOLLOW: int  # Gnu extension if in C library
160 O_NOATIME: int  # Gnu extension if in C library
161 O_PATH: int  # Gnu extension if in C library
162 O_TMPFILE: int  # Gnu extension if in C library
163 O_LARGEFILE: int  # Gnu extension if in C library
164
165 curdir: str
166 pardir: str
167 sep: str
168 if sys.platform == "win32":
169     altsep: str
170 else:
171     altsep: str | None
172 extsep: str
173 pathsep: str
174 defpath: str
175 linesep: str
176 devnull: str
177 name: str
178
179 F_OK: int
180 R_OK: int
181 W_OK: int
182 X_OK: int
183
184 _EnvironCodeFunc = Callable[[AnyStr], AnyStr]
185
186 class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]):
187     encodekey: _EnvironCodeFunc[AnyStr]
188     decodekey: _EnvironCodeFunc[AnyStr]
189     encodevalue: _EnvironCodeFunc[AnyStr]
190     decodevalue: _EnvironCodeFunc[AnyStr]
191     if sys.version_info >= (3, 9):
192         def __init__(
193             self,
194             data: MutableMapping[AnyStr, AnyStr],
195             encodekey: _EnvironCodeFunc[AnyStr],
196             decodekey: _EnvironCodeFunc[AnyStr],
197             encodevalue: _EnvironCodeFunc[AnyStr],
198             decodevalue: _EnvironCodeFunc[AnyStr],
199         ) -> None: ...
200     else:
201         putenv: Callable[[AnyStr, AnyStr], None]
202         unsetenv: Callable[[AnyStr, AnyStr], None]
203         def __init__(
204             self,
205             data: MutableMapping[AnyStr, AnyStr],
206             encodekey: _EnvironCodeFunc[AnyStr],
207             decodekey: _EnvironCodeFunc[AnyStr],
208             encodevalue: _EnvironCodeFunc[AnyStr],
209             decodevalue: _EnvironCodeFunc[AnyStr],
210             putenv: Callable[[AnyStr, AnyStr], None],
211             unsetenv: Callable[[AnyStr, AnyStr], None],
212         ) -> None: ...
213     def setdefault(self, key: AnyStr, value: AnyStr) -> AnyStr: ...  # type: ignore
214     def copy(self) -> dict[AnyStr, AnyStr]: ...
215     def __delitem__(self, key: AnyStr) -> None: ...
216     def __getitem__(self, key: AnyStr) -> AnyStr: ...
217     def __setitem__(self, key: AnyStr, value: AnyStr) -> None: ...
218     def __iter__(self) -> Iterator[AnyStr]: ...
219     def __len__(self) -> int: ...
220
221 environ: _Environ[str]
222 if sys.platform != "win32":
223     environb: _Environ[bytes]
224
225 if sys.platform != "win32":
226     confstr_names: dict[str, int]
227     pathconf_names: dict[str, int]
228     sysconf_names: dict[str, int]
229
230     EX_OK: int
231     EX_USAGE: int
232     EX_DATAERR: int
233     EX_NOINPUT: int
234     EX_NOUSER: int
235     EX_NOHOST: int
236     EX_UNAVAILABLE: int
237     EX_SOFTWARE: int
238     EX_OSERR: int
239     EX_OSFILE: int
240     EX_CANTCREAT: int
241     EX_IOERR: int
242     EX_TEMPFAIL: int
243     EX_PROTOCOL: int
244     EX_NOPERM: int
245     EX_CONFIG: int
246     EX_NOTFOUND: int
247
248 P_NOWAIT: int
249 P_NOWAITO: int
250 P_WAIT: int
251 if sys.platform == "win32":
252     P_DETACH: int
253     P_OVERLAY: int
254
255 # wait()/waitpid() options
256 if sys.platform != "win32":
257     WNOHANG: int  # Unix only
258     WCONTINUED: int  # some Unix systems
259     WUNTRACED: int  # Unix only
260
261 TMP_MAX: int  # Undocumented, but used by tempfile
262
263 # ----- os classes (structures) -----
264 @final
265 class stat_result:
266     # For backward compatibility, the return value of stat() is also
267     # accessible as a tuple of at least 10 integers giving the most important
268     # (and portable) members of the stat structure, in the order st_mode,
269     # st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime,
270     # st_ctime. More items may be added at the end by some implementations.
271
272     st_mode: int  # protection bits,
273     st_ino: int  # inode number,
274     st_dev: int  # device,
275     st_nlink: int  # number of hard links,
276     st_uid: int  # user id of owner,
277     st_gid: int  # group id of owner,
278     st_size: int  # size of file, in bytes,
279     st_atime: float  # time of most recent access,
280     st_mtime: float  # time of most recent content modification,
281     st_ctime: float  # platform dependent (time of most recent metadata change on Unix, or the time of creation on Windows)
282     st_atime_ns: int  # time of most recent access, in nanoseconds
283     st_mtime_ns: int  # time of most recent content modification in nanoseconds
284     st_ctime_ns: int  # platform dependent (time of most recent metadata change on Unix, or the time of creation on Windows) in nanoseconds
285     if sys.version_info >= (3, 8) and sys.platform == "win32":
286         st_reparse_tag: int
287     if sys.platform == "win32":
288         st_file_attributes: int
289     def __getitem__(self, i: int) -> int: ...
290     # not documented
291     def __init__(self, tuple: Tuple[int, ...]) -> None: ...
292     # On some Unix systems (such as Linux), the following attributes may also
293     # be available:
294     st_blocks: int  # number of blocks allocated for file
295     st_blksize: int  # filesystem blocksize
296     st_rdev: int  # type of device if an inode device
297     st_flags: int  # user defined flags for file
298
299     # On other Unix systems (such as FreeBSD), the following attributes may be
300     # available (but may be only filled out if root tries to use them):
301     st_gen: int  # file generation number
302     st_birthtime: int  # time of file creation
303
304     # On Mac OS systems, the following attributes may also be available:
305     st_rsize: int
306     st_creator: int
307     st_type: int
308
309 @runtime_checkable
310 class PathLike(Protocol[_AnyStr_co]):
311     def __fspath__(self) -> _AnyStr_co: ...
312     if sys.version_info >= (3, 9):
313         def __class_getitem__(cls, item: Any) -> GenericAlias: ...
314
315 _FdOrAnyPath = Union[int, StrOrBytesPath]
316
317 @final
318 class DirEntry(Generic[AnyStr]):
319     # This is what the scandir iterator yields
320     # The constructor is hidden
321
322     name: AnyStr
323     path: AnyStr
324     def inode(self) -> int: ...
325     def is_dir(self, *, follow_symlinks: bool = ...) -> bool: ...
326     def is_file(self, *, follow_symlinks: bool = ...) -> bool: ...
327     def is_symlink(self) -> bool: ...
328     def stat(self, *, follow_symlinks: bool = ...) -> stat_result: ...
329     def __fspath__(self) -> AnyStr: ...
330     if sys.version_info >= (3, 9):
331         def __class_getitem__(cls, item: Any) -> GenericAlias: ...
332
333 if sys.platform != "win32":
334     _Tuple10Int = Tuple[int, int, int, int, int, int, int, int, int, int]
335     _Tuple11Int = Tuple[int, int, int, int, int, int, int, int, int, int, int]
336     if sys.version_info >= (3, 7):
337         # f_fsid was added in https://github.com/python/cpython/pull/4571
338         @final
339         class statvfs_result(_Tuple10Int):  # Unix only
340             def __new__(cls, seq: _Tuple10Int | _Tuple11Int, dict: dict[str, int] = ...) -> statvfs_result: ...
341             n_fields: int
342             n_sequence_fields: int
343             n_unnamed_fields: int
344
345             f_bsize: int
346             f_frsize: int
347             f_blocks: int
348             f_bfree: int
349             f_bavail: int
350             f_files: int
351             f_ffree: int
352             f_favail: int
353             f_flag: int
354             f_namemax: int
355             f_fsid: int
356     else:
357         class statvfs_result(_Tuple10Int):  # Unix only
358             n_fields: int
359             n_sequence_fields: int
360             n_unnamed_fields: int
361
362             f_bsize: int
363             f_frsize: int
364             f_blocks: int
365             f_bfree: int
366             f_bavail: int
367             f_files: int
368             f_ffree: int
369             f_favail: int
370             f_flag: int
371             f_namemax: int
372
373 # ----- os function stubs -----
374 def fsencode(filename: StrOrBytesPath) -> bytes: ...
375 def fsdecode(filename: StrOrBytesPath) -> str: ...
376 @overload
377 def fspath(path: str) -> str: ...
378 @overload
379 def fspath(path: bytes) -> bytes: ...
380 @overload
381 def fspath(path: PathLike[AnyStr]) -> AnyStr: ...
382 def get_exec_path(env: Mapping[str, str] | None = ...) -> list[str]: ...
383 def getlogin() -> str: ...
384 def getpid() -> int: ...
385 def getppid() -> int: ...
386 def strerror(__code: int) -> str: ...
387 def umask(__mask: int) -> int: ...
388
389 if sys.platform != "win32":
390     # Unix only
391     def ctermid() -> str: ...
392     def getegid() -> int: ...
393     def geteuid() -> int: ...
394     def getgid() -> int: ...
395     def getgrouplist(__user: str, __group: int) -> list[int]: ...
396     def getgroups() -> list[int]: ...  # Unix only, behaves differently on Mac
397     def initgroups(__username: str, __gid: int) -> None: ...
398     def getpgid(pid: int) -> int: ...
399     def getpgrp() -> int: ...
400     def getpriority(which: int, who: int) -> int: ...
401     def setpriority(which: int, who: int, priority: int) -> None: ...
402     if sys.platform != "darwin":
403         def getresuid() -> tuple[int, int, int]: ...
404         def getresgid() -> tuple[int, int, int]: ...
405     def getuid() -> int: ...
406     def setegid(__egid: int) -> None: ...
407     def seteuid(__euid: int) -> None: ...
408     def setgid(__gid: int) -> None: ...
409     def setgroups(__groups: Sequence[int]) -> None: ...
410     def setpgrp() -> None: ...
411     def setpgid(__pid: int, __pgrp: int) -> None: ...
412     def setregid(__rgid: int, __egid: int) -> None: ...
413     if sys.platform != "darwin":
414         def setresgid(rgid: int, egid: int, sgid: int) -> None: ...
415         def setresuid(ruid: int, euid: int, suid: int) -> None: ...
416     def setreuid(__ruid: int, __euid: int) -> None: ...
417     def getsid(__pid: int) -> int: ...
418     def setsid() -> None: ...
419     def setuid(__uid: int) -> None: ...
420     from posix import uname_result
421     def uname() -> uname_result: ...
422
423 @overload
424 def getenv(key: str) -> str | None: ...
425 @overload
426 def getenv(key: str, default: _T) -> str | _T: ...
427
428 if sys.platform != "win32":
429     @overload
430     def getenvb(key: bytes) -> bytes | None: ...
431     @overload
432     def getenvb(key: bytes, default: _T) -> bytes | _T: ...
433
434 def putenv(__name: bytes | str, __value: bytes | str) -> None: ...
435
436 if sys.platform != "win32":
437     def unsetenv(__name: bytes | str) -> None: ...
438
439 _Opener = Callable[[str, int], int]
440
441 @overload
442 def fdopen(
443     fd: int,
444     mode: OpenTextMode = ...,
445     buffering: int = ...,
446     encoding: str | None = ...,
447     errors: str | None = ...,
448     newline: str | None = ...,
449     closefd: bool = ...,
450     opener: _Opener | None = ...,
451 ) -> _TextIOWrapper: ...
452 @overload
453 def fdopen(
454     fd: int,
455     mode: OpenBinaryMode,
456     buffering: Literal[0],
457     encoding: None = ...,
458     errors: None = ...,
459     newline: None = ...,
460     closefd: bool = ...,
461     opener: _Opener | None = ...,
462 ) -> FileIO: ...
463 @overload
464 def fdopen(
465     fd: int,
466     mode: OpenBinaryModeUpdating,
467     buffering: Literal[-1, 1] = ...,
468     encoding: None = ...,
469     errors: None = ...,
470     newline: None = ...,
471     closefd: bool = ...,
472     opener: _Opener | None = ...,
473 ) -> BufferedRandom: ...
474 @overload
475 def fdopen(
476     fd: int,
477     mode: OpenBinaryModeWriting,
478     buffering: Literal[-1, 1] = ...,
479     encoding: None = ...,
480     errors: None = ...,
481     newline: None = ...,
482     closefd: bool = ...,
483     opener: _Opener | None = ...,
484 ) -> BufferedWriter: ...
485 @overload
486 def fdopen(
487     fd: int,
488     mode: OpenBinaryModeReading,
489     buffering: Literal[-1, 1] = ...,
490     encoding: None = ...,
491     errors: None = ...,
492     newline: None = ...,
493     closefd: bool = ...,
494     opener: _Opener | None = ...,
495 ) -> BufferedReader: ...
496 @overload
497 def fdopen(
498     fd: int,
499     mode: OpenBinaryMode,
500     buffering: int,
501     encoding: None = ...,
502     errors: None = ...,
503     newline: None = ...,
504     closefd: bool = ...,
505     opener: _Opener | None = ...,
506 ) -> BinaryIO: ...
507 @overload
508 def fdopen(
509     fd: int,
510     mode: str,
511     buffering: int = ...,
512     encoding: str | None = ...,
513     errors: str | None = ...,
514     newline: str | None = ...,
515     closefd: bool = ...,
516     opener: _Opener | None = ...,
517 ) -> IO[Any]: ...
518 def close(fd: int) -> None: ...
519 def closerange(__fd_low: int, __fd_high: int) -> None: ...
520 def device_encoding(fd: int) -> str | None: ...
521 def dup(__fd: int) -> int: ...
522
523 if sys.version_info >= (3, 7):
524     def dup2(fd: int, fd2: int, inheritable: bool = ...) -> int: ...
525
526 else:
527     def dup2(fd: int, fd2: int, inheritable: bool = ...) -> None: ...
528
529 def fstat(fd: int) -> stat_result: ...
530 def fsync(fd: FileDescriptorLike) -> None: ...
531 def lseek(__fd: int, __position: int, __how: int) -> int: ...
532 def open(path: StrOrBytesPath, flags: int, mode: int = ..., *, dir_fd: int | None = ...) -> int: ...
533 def pipe() -> tuple[int, int]: ...
534 def read(__fd: int, __length: int) -> bytes: ...
535
536 if sys.platform != "win32":
537     # Unix only
538     def fchmod(fd: int, mode: int) -> None: ...
539     def fchown(fd: int, uid: int, gid: int) -> None: ...
540     if sys.platform != "darwin":
541         def fdatasync(fd: FileDescriptorLike) -> None: ...  # Unix only, not Mac
542     def fpathconf(__fd: int, __name: str | int) -> int: ...
543     def fstatvfs(__fd: int) -> statvfs_result: ...
544     def ftruncate(__fd: int, __length: int) -> None: ...
545     def get_blocking(__fd: int) -> bool: ...
546     def set_blocking(__fd: int, __blocking: bool) -> None: ...
547     def isatty(__fd: int) -> bool: ...
548     def lockf(__fd: int, __command: int, __length: int) -> None: ...
549     def openpty() -> tuple[int, int]: ...  # some flavors of Unix
550     if sys.platform != "darwin":
551         def pipe2(flags: int) -> tuple[int, int]: ...  # some flavors of Unix
552         def posix_fallocate(fd: int, offset: int, length: int) -> None: ...
553         def posix_fadvise(fd: int, offset: int, length: int, advice: int) -> None: ...
554     def pread(__fd: int, __length: int, __offset: int) -> bytes: ...
555     def pwrite(__fd: int, __buffer: bytes, __offset: int) -> int: ...
556     @overload
557     def sendfile(out_fd: int, in_fd: int, offset: int | None, count: int) -> int: ...
558     @overload
559     def sendfile(
560         out_fd: int,
561         in_fd: int,
562         offset: int,
563         count: int,
564         headers: Sequence[bytes] = ...,
565         trailers: Sequence[bytes] = ...,
566         flags: int = ...,
567     ) -> int: ...  # FreeBSD and Mac OS X only
568     def readv(__fd: int, __buffers: Sequence[bytearray]) -> int: ...
569     def writev(__fd: int, __buffers: Sequence[bytes]) -> int: ...
570
571 @final
572 class terminal_size(Tuple[int, int]):
573     columns: int
574     lines: int
575
576 def get_terminal_size(fd: int = ...) -> terminal_size: ...
577 def get_inheritable(__fd: int) -> bool: ...
578 def set_inheritable(__fd: int, __inheritable: bool) -> None: ...
579
580 if sys.platform != "win32":
581     # Unix only
582     def tcgetpgrp(__fd: int) -> int: ...
583     def tcsetpgrp(__fd: int, __pgid: int) -> None: ...
584     def ttyname(__fd: int) -> str: ...
585
586 def write(__fd: int, __data: bytes) -> int: ...
587 def access(
588     path: _FdOrAnyPath, mode: int, *, dir_fd: int | None = ..., effective_ids: bool = ..., follow_symlinks: bool = ...
589 ) -> bool: ...
590 def chdir(path: _FdOrAnyPath) -> None: ...
591
592 if sys.platform != "win32":
593     def fchdir(fd: FileDescriptorLike) -> None: ...
594
595 def getcwd() -> str: ...
596 def getcwdb() -> bytes: ...
597 def chmod(path: _FdOrAnyPath, mode: int, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> None: ...
598
599 if sys.platform != "win32":
600     def chflags(path: StrOrBytesPath, flags: int, follow_symlinks: bool = ...) -> None: ...  # some flavors of Unix
601     def chown(
602         path: _FdOrAnyPath, uid: int, gid: int, *, dir_fd: int | None = ..., follow_symlinks: bool = ...
603     ) -> None: ...  # Unix only
604
605 if sys.platform != "win32":
606     # Unix only
607     def chroot(path: StrOrBytesPath) -> None: ...
608     def lchflags(path: StrOrBytesPath, flags: int) -> None: ...
609     def lchmod(path: StrOrBytesPath, mode: int) -> None: ...
610     def lchown(path: StrOrBytesPath, uid: int, gid: int) -> None: ...
611
612 def link(
613     src: StrOrBytesPath,
614     dst: StrOrBytesPath,
615     *,
616     src_dir_fd: int | None = ...,
617     dst_dir_fd: int | None = ...,
618     follow_symlinks: bool = ...,
619 ) -> None: ...
620 def lstat(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> stat_result: ...
621 def mkdir(path: StrOrBytesPath, mode: int = ..., *, dir_fd: int | None = ...) -> None: ...
622
623 if sys.platform != "win32":
624     def mkfifo(path: StrOrBytesPath, mode: int = ..., *, dir_fd: int | None = ...) -> None: ...  # Unix only
625
626 def makedirs(name: StrOrBytesPath, mode: int = ..., exist_ok: bool = ...) -> None: ...
627
628 if sys.platform != "win32":
629     def mknod(path: StrOrBytesPath, mode: int = ..., device: int = ..., *, dir_fd: int | None = ...) -> None: ...
630     def major(__device: int) -> int: ...
631     def minor(__device: int) -> int: ...
632     def makedev(__major: int, __minor: int) -> int: ...
633     def pathconf(path: _FdOrAnyPath, name: str | int) -> int: ...  # Unix only
634
635 def readlink(path: AnyStr | PathLike[AnyStr], *, dir_fd: int | None = ...) -> AnyStr: ...
636 def remove(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> None: ...
637 def removedirs(name: StrOrBytesPath) -> None: ...
638 def rename(src: StrOrBytesPath, dst: StrOrBytesPath, *, src_dir_fd: int | None = ..., dst_dir_fd: int | None = ...) -> None: ...
639 def renames(old: StrOrBytesPath, new: StrOrBytesPath) -> None: ...
640 def replace(src: StrOrBytesPath, dst: StrOrBytesPath, *, src_dir_fd: int | None = ..., dst_dir_fd: int | None = ...) -> None: ...
641 def rmdir(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> None: ...
642
643 class _ScandirIterator(Iterator[DirEntry[AnyStr]], AbstractContextManager[_ScandirIterator[AnyStr]]):
644     def __next__(self) -> DirEntry[AnyStr]: ...
645     def close(self) -> None: ...
646
647 if sys.version_info >= (3, 7):
648     @overload
649     def scandir(path: None = ...) -> _ScandirIterator[str]: ...
650     @overload
651     def scandir(path: int) -> _ScandirIterator[str]: ...
652     @overload
653     def scandir(path: AnyStr | PathLike[AnyStr]) -> _ScandirIterator[AnyStr]: ...
654
655 else:
656     @overload
657     def scandir(path: None = ...) -> _ScandirIterator[str]: ...
658     @overload
659     def scandir(path: AnyStr | PathLike[AnyStr]) -> _ScandirIterator[AnyStr]: ...
660
661 def stat(path: _FdOrAnyPath, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> stat_result: ...
662
663 if sys.version_info < (3, 7):
664     @overload
665     def stat_float_times() -> bool: ...
666     @overload
667     def stat_float_times(__newvalue: bool) -> None: ...
668
669 if sys.platform != "win32":
670     def statvfs(path: _FdOrAnyPath) -> statvfs_result: ...  # Unix only
671
672 def symlink(src: StrOrBytesPath, dst: StrOrBytesPath, target_is_directory: bool = ..., *, dir_fd: int | None = ...) -> None: ...
673
674 if sys.platform != "win32":
675     def sync() -> None: ...  # Unix only
676
677 def truncate(path: _FdOrAnyPath, length: int) -> None: ...  # Unix only up to version 3.4
678 def unlink(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> None: ...
679 def utime(
680     path: _FdOrAnyPath,
681     times: tuple[int, int] | tuple[float, float] | None = ...,
682     *,
683     ns: tuple[int, int] = ...,
684     dir_fd: int | None = ...,
685     follow_symlinks: bool = ...,
686 ) -> None: ...
687
688 _OnError = Callable[[OSError], Any]
689
690 def walk(
691     top: AnyStr | PathLike[AnyStr], topdown: bool = ..., onerror: _OnError | None = ..., followlinks: bool = ...
692 ) -> Iterator[tuple[AnyStr, list[AnyStr], list[AnyStr]]]: ...
693
694 if sys.platform != "win32":
695     if sys.version_info >= (3, 7):
696         @overload
697         def fwalk(
698             top: StrPath = ...,
699             topdown: bool = ...,
700             onerror: _OnError | None = ...,
701             *,
702             follow_symlinks: bool = ...,
703             dir_fd: int | None = ...,
704         ) -> Iterator[tuple[str, list[str], list[str], int]]: ...
705         @overload
706         def fwalk(
707             top: bytes,
708             topdown: bool = ...,
709             onerror: _OnError | None = ...,
710             *,
711             follow_symlinks: bool = ...,
712             dir_fd: int | None = ...,
713         ) -> Iterator[tuple[bytes, list[bytes], list[bytes], int]]: ...
714     else:
715         def fwalk(
716             top: StrPath = ...,
717             topdown: bool = ...,
718             onerror: _OnError | None = ...,
719             *,
720             follow_symlinks: bool = ...,
721             dir_fd: int | None = ...,
722         ) -> Iterator[tuple[str, list[str], list[str], int]]: ...
723     if sys.platform == "linux":
724         def getxattr(path: _FdOrAnyPath, attribute: StrOrBytesPath, *, follow_symlinks: bool = ...) -> bytes: ...
725         def listxattr(path: _FdOrAnyPath | None = ..., *, follow_symlinks: bool = ...) -> list[str]: ...
726         def removexattr(path: _FdOrAnyPath, attribute: StrOrBytesPath, *, follow_symlinks: bool = ...) -> None: ...
727         def setxattr(
728             path: _FdOrAnyPath, attribute: StrOrBytesPath, value: bytes, flags: int = ..., *, follow_symlinks: bool = ...
729         ) -> None: ...
730
731 def abort() -> NoReturn: ...
732
733 # These are defined as execl(file, *args) but the first *arg is mandatory.
734 def execl(file: StrOrBytesPath, __arg0: StrOrBytesPath, *args: StrOrBytesPath) -> NoReturn: ...
735 def execlp(file: StrOrBytesPath, __arg0: StrOrBytesPath, *args: StrOrBytesPath) -> NoReturn: ...
736
737 # These are: execle(file, *args, env) but env is pulled from the last element of the args.
738 def execle(file: StrOrBytesPath, __arg0: StrOrBytesPath, *args: Any) -> NoReturn: ...
739 def execlpe(file: StrOrBytesPath, __arg0: StrOrBytesPath, *args: Any) -> NoReturn: ...
740
741 # The docs say `args: tuple or list of strings`
742 # The implementation enforces tuple or list so we can't use Sequence.
743 # Not separating out PathLike[str] and PathLike[bytes] here because it doesn't make much difference
744 # in practice, and doing so would explode the number of combinations in this already long union.
745 # All these combinations are necessary due to list being invariant.
746 _ExecVArgs = Union[
747     Tuple[StrOrBytesPath, ...],
748     List[bytes],
749     List[str],
750     List[PathLike[Any]],
751     List[Union[bytes, str]],
752     List[Union[bytes, PathLike[Any]]],
753     List[Union[str, PathLike[Any]]],
754     List[Union[bytes, str, PathLike[Any]]],
755 ]
756 _ExecEnv = Union[Mapping[bytes, Union[bytes, str]], Mapping[str, Union[bytes, str]]]
757
758 def execv(__path: StrOrBytesPath, __argv: _ExecVArgs) -> NoReturn: ...
759 def execve(path: _FdOrAnyPath, argv: _ExecVArgs, env: _ExecEnv) -> NoReturn: ...
760 def execvp(file: StrOrBytesPath, args: _ExecVArgs) -> NoReturn: ...
761 def execvpe(file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> NoReturn: ...
762 def _exit(status: int) -> NoReturn: ...
763 def kill(__pid: int, __signal: int) -> None: ...
764
765 if sys.platform != "win32":
766     # Unix only
767     def fork() -> int: ...
768     def forkpty() -> tuple[int, int]: ...  # some flavors of Unix
769     def killpg(__pgid: int, __signal: int) -> None: ...
770     def nice(__increment: int) -> int: ...
771     if sys.platform != "darwin":
772         def plock(op: int) -> None: ...  # ???op is int?
773
774 class _wrap_close(_TextIOWrapper):
775     def __init__(self, stream: _TextIOWrapper, proc: Popen[str]) -> None: ...
776     def close(self) -> int | None: ...  # type: ignore
777
778 def popen(cmd: str, mode: str = ..., buffering: int = ...) -> _wrap_close: ...
779 def spawnl(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: StrOrBytesPath) -> int: ...
780 def spawnle(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: Any) -> int: ...  # Imprecise sig
781
782 if sys.platform != "win32":
783     def spawnv(mode: int, file: StrOrBytesPath, args: _ExecVArgs) -> int: ...
784     def spawnve(mode: int, file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> int: ...
785
786 else:
787     def spawnv(__mode: int, __path: StrOrBytesPath, __argv: _ExecVArgs) -> int: ...
788     def spawnve(__mode: int, __path: StrOrBytesPath, __argv: _ExecVArgs, __env: _ExecEnv) -> int: ...
789
790 def system(command: StrOrBytesPath) -> int: ...
791 def times() -> times_result: ...
792 def waitpid(__pid: int, __options: int) -> tuple[int, int]: ...
793
794 if sys.platform == "win32":
795     def startfile(path: StrOrBytesPath, operation: str | None = ...) -> None: ...
796
797 else:
798     # Unix only
799     def spawnlp(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: StrOrBytesPath) -> int: ...
800     def spawnlpe(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: Any) -> int: ...  # Imprecise signature
801     def spawnvp(mode: int, file: StrOrBytesPath, args: _ExecVArgs) -> int: ...
802     def spawnvpe(mode: int, file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> int: ...
803     def wait() -> tuple[int, int]: ...  # Unix only
804     if sys.platform != "darwin":
805         from posix import waitid_result
806         def waitid(idtype: int, ident: int, options: int) -> waitid_result: ...
807     def wait3(options: int) -> tuple[int, int, Any]: ...
808     def wait4(pid: int, options: int) -> tuple[int, int, Any]: ...
809     def WCOREDUMP(__status: int) -> bool: ...
810     def WIFCONTINUED(status: int) -> bool: ...
811     def WIFSTOPPED(status: int) -> bool: ...
812     def WIFSIGNALED(status: int) -> bool: ...
813     def WIFEXITED(status: int) -> bool: ...
814     def WEXITSTATUS(status: int) -> int: ...
815     def WSTOPSIG(status: int) -> int: ...
816     def WTERMSIG(status: int) -> int: ...
817     if sys.version_info >= (3, 8):
818         from posix import posix_spawn as posix_spawn, posix_spawnp as posix_spawnp
819
820 if sys.platform != "win32":
821     from posix import sched_param
822     def sched_get_priority_min(policy: int) -> int: ...  # some flavors of Unix
823     def sched_get_priority_max(policy: int) -> int: ...  # some flavors of Unix
824     def sched_yield() -> None: ...  # some flavors of Unix
825     if sys.platform != "darwin":
826         def sched_setscheduler(pid: int, policy: int, param: sched_param) -> None: ...  # some flavors of Unix
827         def sched_getscheduler(pid: int) -> int: ...  # some flavors of Unix
828         def sched_rr_get_interval(pid: int) -> float: ...  # some flavors of Unix
829         def sched_setparam(pid: int, param: sched_param) -> None: ...  # some flavors of Unix
830         def sched_getparam(pid: int) -> sched_param: ...  # some flavors of Unix
831         def sched_setaffinity(pid: int, mask: Iterable[int]) -> None: ...  # some flavors of Unix
832         def sched_getaffinity(pid: int) -> set[int]: ...  # some flavors of Unix
833
834 def cpu_count() -> int | None: ...
835
836 if sys.platform != "win32":
837     # Unix only
838     def confstr(__name: str | int) -> str | None: ...
839     def getloadavg() -> tuple[float, float, float]: ...
840     def sysconf(__name: str | int) -> int: ...
841
842 if sys.platform == "linux":
843     def getrandom(size: int, flags: int = ...) -> bytes: ...
844
845 def urandom(__size: int) -> bytes: ...
846
847 if sys.version_info >= (3, 7) and sys.platform != "win32":
848     def register_at_fork(
849         *,
850         before: Callable[..., Any] | None = ...,
851         after_in_parent: Callable[..., Any] | None = ...,
852         after_in_child: Callable[..., Any] | None = ...,
853     ) -> None: ...
854
855 if sys.version_info >= (3, 8):
856     if sys.platform == "win32":
857         class _AddedDllDirectory:
858             path: str | None
859             def __init__(self, path: str | None, cookie: _T, remove_dll_directory: Callable[[_T], Any]) -> None: ...
860             def close(self) -> None: ...
861             def __enter__(self: Self) -> Self: ...
862             def __exit__(self, *args: Any) -> None: ...
863         def add_dll_directory(path: str) -> _AddedDllDirectory: ...
864     if sys.platform == "linux":
865         MFD_CLOEXEC: int
866         MFD_ALLOW_SEALING: int
867         MFD_HUGETLB: int
868         MFD_HUGE_SHIFT: int
869         MFD_HUGE_MASK: int
870         MFD_HUGE_64KB: int
871         MFD_HUGE_512KB: int
872         MFD_HUGE_1MB: int
873         MFD_HUGE_2MB: int
874         MFD_HUGE_8MB: int
875         MFD_HUGE_16MB: int
876         MFD_HUGE_32MB: int
877         MFD_HUGE_256MB: int
878         MFD_HUGE_512MB: int
879         MFD_HUGE_1GB: int
880         MFD_HUGE_2GB: int
881         MFD_HUGE_16GB: int
882         def memfd_create(name: str, flags: int = ...) -> int: ...