2 from _typeshed import (
6 OpenBinaryModeUpdating,
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
39 from typing_extensions import Literal, final
41 from . import path as _path
43 if sys.version_info >= (3, 9):
44 from types import GenericAlias
46 # This unnecessary alias is to work around various errors
50 _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True)
52 # ----- os variables -----
56 supports_bytes_environ: bool
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]]
63 if sys.platform != "win32":
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
86 if sys.platform == "linux":
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
112 if sys.platform != "win32":
120 if sys.platform == "linux":
126 if sys.platform != "win32":
127 SEEK_DATA: int # some flavors of Unix
128 SEEK_HOLE: int # some flavors of Unix
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
168 if sys.platform == "win32":
184 _EnvironCodeFunc = Callable[[AnyStr], AnyStr]
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):
194 data: MutableMapping[AnyStr, AnyStr],
195 encodekey: _EnvironCodeFunc[AnyStr],
196 decodekey: _EnvironCodeFunc[AnyStr],
197 encodevalue: _EnvironCodeFunc[AnyStr],
198 decodevalue: _EnvironCodeFunc[AnyStr],
201 putenv: Callable[[AnyStr, AnyStr], None]
202 unsetenv: Callable[[AnyStr, AnyStr], None]
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],
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: ...
221 environ: _Environ[str]
222 if sys.platform != "win32":
223 environb: _Environ[bytes]
225 if sys.platform != "win32":
226 confstr_names: dict[str, int]
227 pathconf_names: dict[str, int]
228 sysconf_names: dict[str, int]
251 if sys.platform == "win32":
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
261 TMP_MAX: int # Undocumented, but used by tempfile
263 # ----- os classes (structures) -----
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.
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":
287 if sys.platform == "win32":
288 st_file_attributes: int
289 def __getitem__(self, i: int) -> int: ...
291 def __init__(self, tuple: Tuple[int, ...]) -> None: ...
292 # On some Unix systems (such as Linux), the following attributes may also
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
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
304 # On Mac OS systems, the following attributes may also be available:
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: ...
315 _FdOrAnyPath = Union[int, StrOrBytesPath]
318 class DirEntry(Generic[AnyStr]):
319 # This is what the scandir iterator yields
320 # The constructor is hidden
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: ...
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
339 class statvfs_result(_Tuple10Int): # Unix only
340 def __new__(cls, seq: _Tuple10Int | _Tuple11Int, dict: dict[str, int] = ...) -> statvfs_result: ...
342 n_sequence_fields: int
343 n_unnamed_fields: int
357 class statvfs_result(_Tuple10Int): # Unix only
359 n_sequence_fields: int
360 n_unnamed_fields: int
373 # ----- os function stubs -----
374 def fsencode(filename: StrOrBytesPath) -> bytes: ...
375 def fsdecode(filename: StrOrBytesPath) -> str: ...
377 def fspath(path: str) -> str: ...
379 def fspath(path: bytes) -> bytes: ...
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: ...
389 if sys.platform != "win32":
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: ...
424 def getenv(key: str) -> str | None: ...
426 def getenv(key: str, default: _T) -> str | _T: ...
428 if sys.platform != "win32":
430 def getenvb(key: bytes) -> bytes | None: ...
432 def getenvb(key: bytes, default: _T) -> bytes | _T: ...
434 def putenv(__name: bytes | str, __value: bytes | str) -> None: ...
436 if sys.platform != "win32":
437 def unsetenv(__name: bytes | str) -> None: ...
439 _Opener = Callable[[str, int], int]
444 mode: OpenTextMode = ...,
445 buffering: int = ...,
446 encoding: str | None = ...,
447 errors: str | None = ...,
448 newline: str | None = ...,
450 opener: _Opener | None = ...,
451 ) -> _TextIOWrapper: ...
455 mode: OpenBinaryMode,
456 buffering: Literal[0],
457 encoding: None = ...,
461 opener: _Opener | None = ...,
466 mode: OpenBinaryModeUpdating,
467 buffering: Literal[-1, 1] = ...,
468 encoding: None = ...,
472 opener: _Opener | None = ...,
473 ) -> BufferedRandom: ...
477 mode: OpenBinaryModeWriting,
478 buffering: Literal[-1, 1] = ...,
479 encoding: None = ...,
483 opener: _Opener | None = ...,
484 ) -> BufferedWriter: ...
488 mode: OpenBinaryModeReading,
489 buffering: Literal[-1, 1] = ...,
490 encoding: None = ...,
494 opener: _Opener | None = ...,
495 ) -> BufferedReader: ...
499 mode: OpenBinaryMode,
501 encoding: None = ...,
505 opener: _Opener | None = ...,
511 buffering: int = ...,
512 encoding: str | None = ...,
513 errors: str | None = ...,
514 newline: str | None = ...,
516 opener: _Opener | None = ...,
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: ...
523 if sys.version_info >= (3, 7):
524 def dup2(fd: int, fd2: int, inheritable: bool = ...) -> int: ...
527 def dup2(fd: int, fd2: int, inheritable: bool = ...) -> None: ...
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: ...
536 if sys.platform != "win32":
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: ...
557 def sendfile(out_fd: int, in_fd: int, offset: int | None, count: int) -> int: ...
564 headers: Sequence[bytes] = ...,
565 trailers: Sequence[bytes] = ...,
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: ...
572 class terminal_size(Tuple[int, int]):
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: ...
580 if sys.platform != "win32":
582 def tcgetpgrp(__fd: int) -> int: ...
583 def tcsetpgrp(__fd: int, __pgid: int) -> None: ...
584 def ttyname(__fd: int) -> str: ...
586 def write(__fd: int, __data: bytes) -> int: ...
588 path: _FdOrAnyPath, mode: int, *, dir_fd: int | None = ..., effective_ids: bool = ..., follow_symlinks: bool = ...
590 def chdir(path: _FdOrAnyPath) -> None: ...
592 if sys.platform != "win32":
593 def fchdir(fd: FileDescriptorLike) -> None: ...
595 def getcwd() -> str: ...
596 def getcwdb() -> bytes: ...
597 def chmod(path: _FdOrAnyPath, mode: int, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> None: ...
599 if sys.platform != "win32":
600 def chflags(path: StrOrBytesPath, flags: int, follow_symlinks: bool = ...) -> None: ... # some flavors of Unix
602 path: _FdOrAnyPath, uid: int, gid: int, *, dir_fd: int | None = ..., follow_symlinks: bool = ...
603 ) -> None: ... # Unix only
605 if sys.platform != "win32":
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: ...
616 src_dir_fd: int | None = ...,
617 dst_dir_fd: int | None = ...,
618 follow_symlinks: bool = ...,
620 def lstat(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> stat_result: ...
621 def mkdir(path: StrOrBytesPath, mode: int = ..., *, dir_fd: int | None = ...) -> None: ...
623 if sys.platform != "win32":
624 def mkfifo(path: StrOrBytesPath, mode: int = ..., *, dir_fd: int | None = ...) -> None: ... # Unix only
626 def makedirs(name: StrOrBytesPath, mode: int = ..., exist_ok: bool = ...) -> None: ...
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
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: ...
643 class _ScandirIterator(Iterator[DirEntry[AnyStr]], AbstractContextManager[_ScandirIterator[AnyStr]]):
644 def __next__(self) -> DirEntry[AnyStr]: ...
645 def close(self) -> None: ...
647 if sys.version_info >= (3, 7):
649 def scandir(path: None = ...) -> _ScandirIterator[str]: ...
651 def scandir(path: int) -> _ScandirIterator[str]: ...
653 def scandir(path: AnyStr | PathLike[AnyStr]) -> _ScandirIterator[AnyStr]: ...
657 def scandir(path: None = ...) -> _ScandirIterator[str]: ...
659 def scandir(path: AnyStr | PathLike[AnyStr]) -> _ScandirIterator[AnyStr]: ...
661 def stat(path: _FdOrAnyPath, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> stat_result: ...
663 if sys.version_info < (3, 7):
665 def stat_float_times() -> bool: ...
667 def stat_float_times(__newvalue: bool) -> None: ...
669 if sys.platform != "win32":
670 def statvfs(path: _FdOrAnyPath) -> statvfs_result: ... # Unix only
672 def symlink(src: StrOrBytesPath, dst: StrOrBytesPath, target_is_directory: bool = ..., *, dir_fd: int | None = ...) -> None: ...
674 if sys.platform != "win32":
675 def sync() -> None: ... # Unix only
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: ...
681 times: tuple[int, int] | tuple[float, float] | None = ...,
683 ns: tuple[int, int] = ...,
684 dir_fd: int | None = ...,
685 follow_symlinks: bool = ...,
688 _OnError = Callable[[OSError], Any]
691 top: AnyStr | PathLike[AnyStr], topdown: bool = ..., onerror: _OnError | None = ..., followlinks: bool = ...
692 ) -> Iterator[tuple[AnyStr, list[AnyStr], list[AnyStr]]]: ...
694 if sys.platform != "win32":
695 if sys.version_info >= (3, 7):
700 onerror: _OnError | None = ...,
702 follow_symlinks: bool = ...,
703 dir_fd: int | None = ...,
704 ) -> Iterator[tuple[str, list[str], list[str], int]]: ...
709 onerror: _OnError | None = ...,
711 follow_symlinks: bool = ...,
712 dir_fd: int | None = ...,
713 ) -> Iterator[tuple[bytes, list[bytes], list[bytes], int]]: ...
718 onerror: _OnError | None = ...,
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: ...
728 path: _FdOrAnyPath, attribute: StrOrBytesPath, value: bytes, flags: int = ..., *, follow_symlinks: bool = ...
731 def abort() -> NoReturn: ...
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: ...
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: ...
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.
747 Tuple[StrOrBytesPath, ...],
751 List[Union[bytes, str]],
752 List[Union[bytes, PathLike[Any]]],
753 List[Union[str, PathLike[Any]]],
754 List[Union[bytes, str, PathLike[Any]]],
756 _ExecEnv = Union[Mapping[bytes, Union[bytes, str]], Mapping[str, Union[bytes, str]]]
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: ...
765 if sys.platform != "win32":
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?
774 class _wrap_close(_TextIOWrapper):
775 def __init__(self, stream: _TextIOWrapper, proc: Popen[str]) -> None: ...
776 def close(self) -> int | None: ... # type: ignore
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
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: ...
787 def spawnv(__mode: int, __path: StrOrBytesPath, __argv: _ExecVArgs) -> int: ...
788 def spawnve(__mode: int, __path: StrOrBytesPath, __argv: _ExecVArgs, __env: _ExecEnv) -> int: ...
790 def system(command: StrOrBytesPath) -> int: ...
791 def times() -> times_result: ...
792 def waitpid(__pid: int, __options: int) -> tuple[int, int]: ...
794 if sys.platform == "win32":
795 def startfile(path: StrOrBytesPath, operation: str | None = ...) -> None: ...
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
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
834 def cpu_count() -> int | None: ...
836 if sys.platform != "win32":
838 def confstr(__name: str | int) -> str | None: ...
839 def getloadavg() -> tuple[float, float, float]: ...
840 def sysconf(__name: str | int) -> int: ...
842 if sys.platform == "linux":
843 def getrandom(size: int, flags: int = ...) -> bytes: ...
845 def urandom(__size: int) -> bytes: ...
847 if sys.version_info >= (3, 7) and sys.platform != "win32":
848 def register_at_fork(
850 before: Callable[..., Any] | None = ...,
851 after_in_parent: Callable[..., Any] | None = ...,
852 after_in_child: Callable[..., Any] | None = ...,
855 if sys.version_info >= (3, 8):
856 if sys.platform == "win32":
857 class _AddedDllDirectory:
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":
866 MFD_ALLOW_SEALING: int
882 def memfd_create(name: str, flags: int = ...) -> int: ...