diff --git a/stdlib/2/os/__init__.pyi b/stdlib/2/os/__init__.pyi index 641190396..8f7147167 100644 --- a/stdlib/2/os/__init__.pyi +++ b/stdlib/2/os/__init__.pyi @@ -2,7 +2,7 @@ from typing import ( List, Tuple, Union, Sequence, Mapping, IO, Any, Optional, AnyStr, Iterator, - Dict, MutableMapping, NamedTuple, overload + Dict, MutableMapping, NamedTuple, overload, Text ) from . import path from mypy_extensions import NoReturn @@ -93,6 +93,7 @@ WCONTINUED = 0 # some Unix systems WUNTRACED = 0 # Unix only TMP_MAX = 0 +_PathType = Union[bytes, Text] _StatVFS = NamedTuple('_StatVFS', [('f_bsize', int), ('f_frsize', int), ('f_blocks', int), ('f_bfree', int), ('f_bavail', int), ('f_files', int), ('f_ffree', int), ('f_favail', int), ('f_flag', int), @@ -144,7 +145,7 @@ def fsync(fd: int) -> None: ... def ftruncate(fd: int, length: int) -> None: ... def isatty(fd: int) -> bool: ... def lseek(fd: int, pos: int, how: int) -> None: ... -def open(file: unicode, flags: int, mode: int = ...) -> int: ... +def open(file: _PathType, flags: int, mode: int = ...) -> int: ... def openpty() -> Tuple[int, int]: ... def pipe() -> Tuple[int, int]: ... def read(fd: int, n: int) -> str: ... @@ -152,58 +153,58 @@ def tcgetpgrp(fd: int) -> int: ... def tcsetpgrp(fd: int, pg: int) -> None: ... def ttyname(fd: int) -> str: ... def write(fd: int, str: str) -> int: ... -def access(path: unicode, mode: int) -> bool: ... +def access(path: _PathType, mode: int) -> bool: ... def fpathconf(fd: int, name: str) -> None: ... -def chdir(path: unicode) -> None: ... +def chdir(path: _PathType) -> None: ... def fchdir(fd: int) -> None: ... def getcwd() -> str: ... def getcwdu() -> unicode: ... -def chflags(path: unicode, flags: int) -> None: ... -def chroot(path: unicode) -> None: ... -def chmod(path: unicode, mode: int) -> None: ... -def chown(path: unicode, uid: int, gid: int) -> None: ... -def lchflags(path: unicode, flags: int) -> None: ... -def lchmod(path: unicode, uid: int, gid: int) -> None: ... -def lchown(path: unicode, uid: int, gid: int) -> None: ... -def link(source: unicode, link_name: unicode) -> None: ... +def chflags(path: _PathType, flags: int) -> None: ... +def chroot(path: _PathType) -> None: ... +def chmod(path: _PathType, mode: int) -> None: ... +def chown(path: _PathType, uid: int, gid: int) -> None: ... +def lchflags(path: _PathType, flags: int) -> None: ... +def lchmod(path: _PathType, uid: int, gid: int) -> None: ... +def lchown(path: _PathType, uid: int, gid: int) -> None: ... +def link(source: _PathType, link_name: _PathType) -> None: ... def listdir(path: AnyStr) -> List[AnyStr]: ... -def lstat(path: unicode) -> Any: ... -def mkfifo(path: unicode, mode: int = ...) -> None: ... -def mknod(filename: unicode, mode: int = ..., device: int = ...) -> None: ... +def lstat(path: _PathType) -> Any: ... +def mkfifo(path: _PathType, mode: int = ...) -> None: ... +def mknod(filename: _PathType, mode: int = ..., device: int = ...) -> None: ... def major(device: int) -> int: ... def minor(device: int) -> int: ... def makedev(major: int, minor: int) -> int: ... -def mkdir(path: unicode, mode: int = ...) -> None: ... -def makedirs(path: unicode, mode: int = ...) -> None: ... -def pathconf(path: unicode, name: str) -> str: ... +def mkdir(path: _PathType, mode: int = ...) -> None: ... +def makedirs(path: _PathType, mode: int = ...) -> None: ... +def pathconf(path: _PathType, name: str) -> str: ... def readlink(path: AnyStr) -> AnyStr: ... -def remove(path: unicode) -> None: ... -def removedirs(path: unicode) -> None: ... -def rename(src: unicode, dst: unicode) -> None: ... -def renames(old: unicode, new: unicode) -> None: ... -def rmdir(path: unicode) -> None: ... -def stat(path: unicode) -> Any: ... +def remove(path: _PathType) -> None: ... +def removedirs(path: _PathType) -> None: ... +def rename(src: _PathType, dst: _PathType) -> None: ... +def renames(old: _PathType, new: _PathType) -> None: ... +def rmdir(path: _PathType) -> None: ... +def stat(path: _PathType) -> Any: ... @overload def stat_float_times(newvalue: bool = ...) -> None: ... @overload def stat_float_times() -> bool: ... -def statvfs(path: unicode) -> _StatVFS: ... -def symlink(source: unicode, link_name: unicode) -> None: ... -def unlink(path: unicode) -> None: ... -def utime(path: unicode, times: Optional[Tuple[int, int]]) -> None: ... -def walk(top: AnyStr, topdown: bool = ..., onerror: Any = ..., - followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], - List[AnyStr]]]: ... +def statvfs(path: _PathType) -> _StatVFS: ... +def symlink(source: _PathType, link_name: _PathType) -> None: ... +def unlink(path: _PathType) -> None: ... +def utime(path: _PathType, times: Optional[Tuple[int, int]]) -> None: ... +def walk(top: _PathType, topdown: bool = ..., onerror: Any = ..., + followlinks: bool = ...) -> Iterator[Tuple[_PathType, List[_PathType], + List[_PathType]]]: ... def abort() -> None: ... -def execl(file: AnyStr, *args) -> None: ... -def execle(file: AnyStr, *args) -> None: ... -def execlp(file: AnyStr, *args) -> None: ... -def execlpe(file: AnyStr, *args) -> None: ... -def execv(path: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]]) -> None: ... -def execve(path: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]], env: Mapping[AnyStr, AnyStr]) -> None: ... -def execvp(file: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]]) -> None: ... -def execvpe(file: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]], env: Mapping[AnyStr, AnyStr]) -> None: ... +def execl(file: _PathType, *args) -> None: ... +def execle(file: _PathType, *args) -> None: ... +def execlp(file: _PathType, *args) -> None: ... +def execlpe(file: _PathType, *args) -> None: ... +def execv(path: _PathType, args: Union[Tuple[_PathType], List[_PathType]]) -> None: ... +def execve(path: _PathType, args: Union[Tuple[_PathType], List[_PathType]], env: Mapping[_PathType, _PathType]) -> None: ... +def execvp(file: _PathType, args: Union[Tuple[_PathType], List[_PathType]]) -> None: ... +def execvpe(file: _PathType, args: Union[Tuple[_PathType], List[_PathType]], env: Mapping[_PathType, _PathType]) -> None: ... def _exit(n: int) -> NoReturn: ... def fork() -> int: ... def forkpty() -> Tuple[int, int]: ... @@ -216,22 +217,22 @@ def popen2(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any]]: ... def popen3(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any], IO[Any]]: ... def popen4(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any]]: ... -def spawnl(mode: int, path: AnyStr, arg0: AnyStr, *args: AnyStr) -> int: ... -def spawnle(mode: int, path: AnyStr, arg0: AnyStr, +def spawnl(mode: int, path: _PathType, arg0: _PathType, *args: _PathType) -> int: ... +def spawnle(mode: int, path: _PathType, arg0: _PathType, *args: Any) -> int: ... # Imprecise sig -def spawnlp(mode: int, file: AnyStr, arg0: AnyStr, - *args: AnyStr) -> int: ... # Unix only TODO -def spawnlpe(mode: int, file: AnyStr, arg0: AnyStr, *args: Any) -> int: +def spawnlp(mode: int, file: _PathType, arg0: _PathType, + *args: _PathType) -> int: ... # Unix only TODO +def spawnlpe(mode: int, file: _PathType, arg0: _PathType, *args: Any) -> int: ... # Imprecise signature; Unix only TODO -def spawnv(mode: int, path: AnyStr, args: List[AnyStr]) -> int: ... -def spawnve(mode: int, path: AnyStr, args: List[AnyStr], +def spawnv(mode: int, path: _PathType, args: List[_PathType]) -> int: ... +def spawnve(mode: int, path: _PathType, args: List[_PathType], env: Mapping[str, str]) -> int: ... -def spawnvp(mode: int, file: AnyStr, args: List[AnyStr]) -> int: ... # Unix only -def spawnvpe(mode: int, file: AnyStr, args: List[AnyStr], +def spawnvp(mode: int, file: _PathType, args: List[_PathType]) -> int: ... # Unix only +def spawnvpe(mode: int, file: _PathType, args: List[_PathType], env: Mapping[str, str]) -> int: ... # Unix only -def startfile(path: unicode, operation: str = ...) -> None: ... # Windows only -def system(command: unicode) -> int: ... +def startfile(path: _PathType, operation: Optional[str] = ...) -> None: ... # Windows only +def system(command: _PathType) -> int: ... def times() -> Tuple[float, float, float, float, float]: ... def wait() -> Tuple[int, int]: ... # Unix only def waitpid(pid: int, options: int) -> Tuple[int, int]: ... diff --git a/stdlib/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index 71a23cdb2..b52ec3d98 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -8,7 +8,7 @@ from io import TextIOWrapper as _TextIOWrapper import sys from typing import ( Mapping, MutableMapping, Dict, List, Any, Tuple, Iterator, overload, Union, AnyStr, - Optional, Generic, Set, Callable + Optional, Generic, Set, Callable, Text ) from . import path from mypy_extensions import NoReturn @@ -117,6 +117,7 @@ if sys.version_info >= (3, 6): class PathLike: def __fspath__(self) -> AnyStr: ... +_PathType = Union[bytes, Text] if sys.version_info >= (3, 5): class DirEntry: @@ -226,7 +227,7 @@ def setuid(uid: int) -> None: ... # Unix only def strerror(code: int) -> str: ... def umask(mask: int) -> int: ... def uname() -> Tuple[str, str, str, str, str]: ... # Unix only -def unsetenv(key: AnyStr) -> None: ... +def unsetenv(key: _PathType) -> None: ... # Return IO or TextIO def fdopen(fd: int, mode: str = ..., buffering: int = ..., encoding: str = ..., errors: str = ..., newline: str = ..., closefd: bool = ...) -> Any: ... @@ -245,7 +246,7 @@ def fsync(fd: int) -> None: ... def ftruncate(fd: int, length: int) -> None: ... # Unix only def isatty(fd: int) -> bool: ... # Unix only def lseek(fd: int, pos: int, how: int) -> int: ... -def open(file: AnyStr, flags: int, mode: int = ...) -> int: ... +def open(file: _PathType, flags: int, mode: int = ...) -> int: ... def openpty() -> Tuple[int, int]: ... # some flavors of Unix def pipe() -> Tuple[int, int]: ... def read(fd: int, n: int) -> bytes: ... @@ -253,73 +254,73 @@ def tcgetpgrp(fd: int) -> int: ... # Unix only def tcsetpgrp(fd: int, pg: int) -> None: ... # Unix only def ttyname(fd: int) -> str: ... # Unix only def write(fd: int, string: bytes) -> int: ... -def access(path: AnyStr, mode: int) -> bool: ... -def chdir(path: AnyStr) -> None: ... +def access(path: _PathType, mode: int) -> bool: ... +def chdir(path: _PathType) -> None: ... def fchdir(fd: int) -> None: ... def getcwd() -> str: ... def getcwdb() -> bytes: ... def chflags(path: str, flags: int) -> None: ... # Unix only def chroot(path: str) -> None: ... # Unix only -def chmod(path: AnyStr, mode: int) -> None: ... -def chown(path: AnyStr, uid: int, gid: int) -> None: ... # Unix only +def chmod(path: _PathType, mode: int) -> None: ... +def chown(path: _PathType, uid: int, gid: int) -> None: ... # Unix only def lchflags(path: str, flags: int) -> None: ... # Unix only def lchmod(path: str, mode: int) -> None: ... # Unix only def lchown(path: str, uid: int, gid: int) -> None: ... # Unix only -def link(src: AnyStr, link_name: AnyStr) -> None: ... +def link(src: _PathType, link_name: _PathType) -> None: ... @overload def listdir(path: str = ...) -> List[str]: ... @overload def listdir(path: bytes) -> List[bytes]: ... -def lstat(path: AnyStr) -> stat_result: ... +def lstat(path: _PathType) -> stat_result: ... def mkfifo(path: str, mode: int = ...) -> None: ... # Unix only -def mknod(filename: AnyStr, mode: int = ..., device: int = ...) -> None: ... +def mknod(filename: _PathType, mode: int = ..., device: int = ...) -> None: ... def major(device: int) -> int: ... def minor(device: int) -> int: ... def makedev(major: int, minor: int) -> int: ... -def mkdir(path: AnyStr, mode: int = ...) -> None: ... -def makedirs(path: AnyStr, mode: int = ..., +def mkdir(path: _PathType, mode: int = ...) -> None: ... +def makedirs(path: _PathType, mode: int = ..., exist_ok: bool = ...) -> None: ... -def pathconf(path: str, name: str) -> int: ... # Unix only +def pathconf(path: _PathType, name: str) -> int: ... # Unix only def readlink(path: AnyStr) -> AnyStr: ... -def remove(path: AnyStr) -> None: ... -def removedirs(path: AnyStr) -> None: ... -def rename(src: AnyStr, dst: AnyStr) -> None: ... -def renames(old: AnyStr, new: AnyStr) -> None: ... +def remove(path: _PathType) -> None: ... +def removedirs(path: _PathType) -> None: ... +def rename(src: _PathType, dst: _PathType) -> None: ... +def renames(old: _PathType, new: _PathType) -> None: ... if sys.version_info >= (3, 3): - def replace(src: AnyStr, dst: AnyStr) -> None: ... -def rmdir(path: AnyStr) -> None: ... + def replace(src: _PathType, dst: _PathType) -> None: ... +def rmdir(path: _PathType) -> None: ... if sys.version_info >= (3, 5): @overload def scandir(path: str = ...) -> Iterator[DirEntry]: ... @overload def scandir(path: bytes) -> Iterator[DirEntry]: ... -def stat(path: AnyStr) -> stat_result: ... +def stat(path: _PathType) -> stat_result: ... def stat_float_times(newvalue: Union[bool, None] = ...) -> bool: ... def statvfs(path: str) -> statvfs_result: ... # Unix only -def symlink(source: AnyStr, link_name: AnyStr, +def symlink(source: _PathType, link_name: _PathType, target_is_directory: bool = ...) -> None: ... # final argument in Windows only -def unlink(path: AnyStr) -> None: ... -def utime(path: AnyStr, times: Union[Tuple[int, int], Tuple[float, float]] = ...) -> None: ... +def unlink(path: _PathType) -> None: ... +def utime(path: _PathType, times: Union[Tuple[int, int], Tuple[float, float]] = ...) -> None: ... # TODO onerror: function from OSError to void -def walk(top: AnyStr, topdown: bool = ..., onerror: Any = ..., - followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], - List[AnyStr]]]: ... +def walk(top: _PathType, topdown: bool = ..., onerror: Any = ..., + followlinks: bool = ...) -> Iterator[Tuple[_PathType, List[_PathType], + List[_PathType]]]: ... def abort() -> 'None': ... -def execl(path: AnyStr, arg0: AnyStr, *args: AnyStr) -> None: ... -def execle(path: AnyStr, arg0: AnyStr, +def execl(path: _PathType, arg0: _PathType, *args: _PathType) -> None: ... +def execle(path: _PathType, arg0: _PathType, *args: Any) -> None: ... # Imprecise signature -def execlp(path: AnyStr, arg0: AnyStr, *args: AnyStr) -> None: ... -def execlpe(path: AnyStr, arg0: AnyStr, +def execlp(path: _PathType, arg0: _PathType, *args: _PathType) -> None: ... +def execlpe(path: _PathType, arg0: _PathType, *args: Any) -> None: ... # Imprecise signature -def execv(path: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]]) -> None: ... -def execve(path: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]], env: Mapping[AnyStr, AnyStr]) -> None: ... -def execvp(file: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]]) -> None: ... -def execvpe(file: AnyStr, args: Union[Tuple[AnyStr], List[AnyStr]], +def execv(path: _PathType, args: Union[Tuple[_PathType], List[_PathType]]) -> None: ... +def execve(path: _PathType, args: Union[Tuple[_PathType], List[_PathType]], env: Mapping[_PathType, _PathType]) -> None: ... +def execvp(file: _PathType, args: Union[Tuple[_PathType], List[_PathType]]) -> None: ... +def execvpe(file: _PathType, args: Union[Tuple[_PathType], List[_PathType]], env: Mapping[str, str]) -> None: ... def _exit(n: int) -> NoReturn: ... def fork() -> int: ... # Unix only @@ -335,22 +336,22 @@ class popen(_TextIOWrapper): bufsize: int = ...) -> None: ... def close(self) -> Any: ... # may return int -def spawnl(mode: int, path: AnyStr, arg0: AnyStr, *args: AnyStr) -> int: ... -def spawnle(mode: int, path: AnyStr, arg0: AnyStr, +def spawnl(mode: int, path: _PathType, arg0: _PathType, *args: _PathType) -> int: ... +def spawnle(mode: int, path: _PathType, arg0: _PathType, *args: Any) -> int: ... # Imprecise sig -def spawnlp(mode: int, file: AnyStr, arg0: AnyStr, - *args: AnyStr) -> int: ... # Unix only TODO -def spawnlpe(mode: int, file: AnyStr, arg0: AnyStr, *args: Any) -> int: +def spawnlp(mode: int, file: _PathType, arg0: _PathType, + *args: _PathType) -> int: ... # Unix only TODO +def spawnlpe(mode: int, file: _PathType, arg0: _PathType, *args: Any) -> int: ... # Imprecise signature; Unix only TODO -def spawnv(mode: int, path: AnyStr, args: List[AnyStr]) -> int: ... -def spawnve(mode: int, path: AnyStr, args: List[AnyStr], +def spawnv(mode: int, path: _PathType, args: List[_PathType]) -> int: ... +def spawnve(mode: int, path: _PathType, args: List[_PathType], env: Mapping[str, str]) -> int: ... -def spawnvp(mode: int, file: AnyStr, args: List[AnyStr]) -> int: ... # Unix only -def spawnvpe(mode: int, file: AnyStr, args: List[AnyStr], +def spawnvp(mode: int, file: _PathType, args: List[_PathType]) -> int: ... # Unix only +def spawnvpe(mode: int, file: _PathType, args: List[_PathType], env: Mapping[str, str]) -> int: ... # Unix only -def startfile(path: str, operation: Union[str, None] = ...) -> None: ... # Windows only -def system(command: AnyStr) -> int: ... +def startfile(path: _PathType, operation: Optional[str] = ...) -> None: ... # Windows only +def system(command: _PathType) -> int: ... def times() -> Tuple[float, float, float, float, float]: ... def wait() -> Tuple[int, int]: ... # Unix only def waitpid(pid: int, options: int) -> Tuple[int, int]: ... @@ -381,7 +382,7 @@ WNOWAIT = 0 if sys.version_info >= (3, 3): def sync() -> None: ... # Unix only - def truncate(path: Union[AnyStr, int], length: int) -> None: ... # Unix only up to version 3.4 + def truncate(path: Union[_PathType, int], length: int) -> None: ... # Unix only up to version 3.4 def fwalk(top: AnyStr = ..., topdown: bool = ..., onerror: Callable = ..., *, follow_symlinks: bool = ...,