From 66fbb26aec350d118634f5981372832f40f13332 Mon Sep 17 00:00:00 2001 From: David Euresti Date: Mon, 20 Mar 2017 21:56:14 -0700 Subject: [PATCH 1/5] Use Union[bytes, Text] in os.pyi In order to unify these two versions I'm making all paths be _PathType = Union[bytes, Text] Fixes #439 --- stdlib/2/os/__init__.pyi | 101 ++++++++++++++++++++------------------- stdlib/3/os/__init__.pyi | 93 +++++++++++++++++------------------ 2 files changed, 98 insertions(+), 96 deletions(-) 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 = ..., From eb5d8c9cf2074fb0bfa54c0e4217b3e64629ef1c Mon Sep 17 00:00:00 2001 From: David Euresti Date: Mon, 20 Mar 2017 22:12:58 -0700 Subject: [PATCH 2/5] Missed some that were marked as str --- stdlib/3/os/__init__.pyi | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/stdlib/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index b52ec3d98..8e942a364 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -259,13 +259,13 @@ 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 chflags(path: _PathType, flags: int) -> None: ... # Unix only +def chroot(path: _PathType) -> 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 lchflags(path: _PathType, flags: int) -> None: ... # Unix only +def lchmod(path: _PathType, mode: int) -> None: ... # Unix only +def lchown(path: _PathType, uid: int, gid: int) -> None: ... # Unix only def link(src: _PathType, link_name: _PathType) -> None: ... @overload @@ -274,7 +274,7 @@ def listdir(path: str = ...) -> List[str]: ... def listdir(path: bytes) -> List[bytes]: ... def lstat(path: _PathType) -> stat_result: ... -def mkfifo(path: str, mode: int = ...) -> None: ... # Unix only +def mkfifo(path: _PathType, mode: int = ...) -> None: ... # Unix only def mknod(filename: _PathType, mode: int = ..., device: int = ...) -> None: ... def major(device: int) -> int: ... def minor(device: int) -> int: ... @@ -298,7 +298,7 @@ if sys.version_info >= (3, 5): def scandir(path: bytes) -> Iterator[DirEntry]: ... def stat(path: _PathType) -> stat_result: ... def stat_float_times(newvalue: Union[bool, None] = ...) -> bool: ... -def statvfs(path: str) -> statvfs_result: ... # Unix only +def statvfs(path: _PathType) -> statvfs_result: ... # Unix only def symlink(source: _PathType, link_name: _PathType, target_is_directory: bool = ...) -> None: ... # final argument in Windows only From a4d70e5b0108008876de365722f3aa5d8f5a7c2f Mon Sep 17 00:00:00 2001 From: David Euresti Date: Mon, 20 Mar 2017 22:26:06 -0700 Subject: [PATCH 3/5] Bring some things back to Union types --- stdlib/2/os/__init__.pyi | 22 +++++++++++----------- stdlib/3/os/__init__.pyi | 31 +++++++++++++++---------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/stdlib/2/os/__init__.pyi b/stdlib/2/os/__init__.pyi index 8f7147167..4f7575d0d 100644 --- a/stdlib/2/os/__init__.pyi +++ b/stdlib/2/os/__init__.pyi @@ -192,19 +192,19 @@ 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 walk(top: AnyStr, topdown: bool = ..., onerror: Any = ..., + followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], + List[Anystr]]]: ... def abort() -> 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 execv(path: _PathType, args: Union[Tuple[Union[bytes, Text]], List[Union[bytes, Text]]]) -> None: ... +def execve(path: _PathType, args: Union[Tuple[Union[bytes, Text]], List[Union[bytes, Text]]], env: Mapping[str, str]) -> None: ... +def execvp(file: _PathType, args: Union[Tuple[Union[bytes, Text]], List[Union[bytes, Text]]]) -> None: ... +def execvpe(file: _PathType, args: Union[Tuple[Union[bytes, Text]], List[Union[bytes, Text]]], env: Mapping[str, str]) -> None: ... def _exit(n: int) -> NoReturn: ... def fork() -> int: ... def forkpty() -> Tuple[int, int]: ... @@ -224,11 +224,11 @@ 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: _PathType, args: List[_PathType]) -> int: ... -def spawnve(mode: int, path: _PathType, args: List[_PathType], +def spawnv(mode: int, path: _PathType, args: List[Union[bytes, Text]]) -> int: ... +def spawnve(mode: int, path: _PathType, args: List[Union[bytes, Text]], env: Mapping[str, str]) -> int: ... -def spawnvp(mode: int, file: _PathType, args: List[_PathType]) -> int: ... # Unix only -def spawnvpe(mode: int, file: _PathType, args: List[_PathType], +def spawnvp(mode: int, file: _PathType, args: List[Union[bytes, Text]]) -> int: ... # Unix only +def spawnvpe(mode: int, file: _PathType, args: List[Union[bytes, Text]], env: Mapping[str, str]) -> int: ... # Unix only def startfile(path: _PathType, operation: Optional[str] = ...) -> None: ... # Windows only diff --git a/stdlib/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index 8e942a364..ad537c9a3 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -306,22 +306,21 @@ 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: _PathType, topdown: bool = ..., onerror: Any = ..., - followlinks: bool = ...) -> Iterator[Tuple[_PathType, List[_PathType], - List[_PathType]]]: ... +def walk(top: AnyStr, topdown: bool = ..., onerror: Any = ..., + followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], + List[AnyStr]]]: ... def abort() -> 'None': ... -def execl(path: _PathType, arg0: _PathType, *args: _PathType) -> None: ... -def execle(path: _PathType, arg0: _PathType, +def execl(path: _PathType, arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> None: ... +def execle(path: _PathType, arg0: Union[bytes, Text], *args: Any) -> None: ... # Imprecise signature -def execlp(path: _PathType, arg0: _PathType, *args: _PathType) -> None: ... -def execlpe(path: _PathType, arg0: _PathType, +def execlp(path: _PathType, arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> None: ... +def execlpe(path: _PathType, arg0: Union[bytes, Text], *args: Any) -> None: ... # Imprecise signature -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 execv(path: _PathType, args: Union[Tuple[Union[bytes, Text]], List[Union[bytes, Text]]]) -> None: ... +def execve(path: _PathType, args: Union[Tuple[Union[bytes, Text]], List[Union[bytes, Text]]], env: Mapping[str, str]) -> None: ... +def execvp(file: _PathType, args: Union[Tuple[Union[bytes, Text]], List[Union[bytes, Text]]]) -> None: ... +def execvpe(file: _PathType, args: Union[Tuple[Union[bytes, Text]], List[Union[bytes, Text]]], env: Mapping[str, str]) -> None: ... def _exit(n: int) -> NoReturn: ... def fork() -> int: ... # Unix only def forkpty() -> Tuple[int, int]: ... # some flavors of Unix @@ -343,11 +342,11 @@ 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: _PathType, args: List[_PathType]) -> int: ... -def spawnve(mode: int, path: _PathType, args: List[_PathType], +def spawnv(mode: int, path: _PathType, args: List[Union[bytes, Text]]) -> int: ... +def spawnve(mode: int, path: _PathType, args: List[Union[bytes, Text]], env: Mapping[str, str]) -> int: ... -def spawnvp(mode: int, file: _PathType, args: List[_PathType]) -> int: ... # Unix only -def spawnvpe(mode: int, file: _PathType, args: List[_PathType], +def spawnvp(mode: int, file: _PathType, args: List[Union[bytes, Text]]) -> int: ... # Unix only +def spawnvpe(mode: int, file: _PathType, args: List[Union[bytes, Text]], env: Mapping[str, str]) -> int: ... # Unix only def startfile(path: _PathType, operation: Optional[str] = ...) -> None: ... # Windows only From 2804788efa5949163c69a8024b48ef8b0b623bb8 Mon Sep 17 00:00:00 2001 From: David Euresti Date: Mon, 20 Mar 2017 22:29:43 -0700 Subject: [PATCH 4/5] Bring some things back to Union types --- stdlib/2/os/__init__.pyi | 10 +++++----- stdlib/3/os/__init__.pyi | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/stdlib/2/os/__init__.pyi b/stdlib/2/os/__init__.pyi index 4f7575d0d..9c4c91444 100644 --- a/stdlib/2/os/__init__.pyi +++ b/stdlib/2/os/__init__.pyi @@ -217,12 +217,12 @@ 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: _PathType, arg0: _PathType, *args: _PathType) -> int: ... -def spawnle(mode: int, path: _PathType, arg0: _PathType, +def spawnl(mode: int, path: _PathType, arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> int: ... +def spawnle(mode: int, path: _PathType, arg0: Union[bytes, Text], *args: Any) -> int: ... # Imprecise sig -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: +def spawnlp(mode: int, file: _PathType, arg0: Union[bytes, Text], + *args: Union[bytes, Text]) -> int: ... # Unix only TODO +def spawnlpe(mode: int, file: _PathType, arg0: Union[bytes, Text], *args: Any) -> int: ... # Imprecise signature; Unix only TODO def spawnv(mode: int, path: _PathType, args: List[Union[bytes, Text]]) -> int: ... def spawnve(mode: int, path: _PathType, args: List[Union[bytes, Text]], diff --git a/stdlib/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index ad537c9a3..ccd69a658 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -335,12 +335,12 @@ class popen(_TextIOWrapper): bufsize: int = ...) -> None: ... def close(self) -> Any: ... # may return int -def spawnl(mode: int, path: _PathType, arg0: _PathType, *args: _PathType) -> int: ... -def spawnle(mode: int, path: _PathType, arg0: _PathType, +def spawnl(mode: int, path: _PathType, arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> int: ... +def spawnle(mode: int, path: _PathType, arg0: Union[bytes, Text], *args: Any) -> int: ... # Imprecise sig -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: +def spawnlp(mode: int, file: _PathType, arg0: Union[bytes, Text], + *args: Union[bytes, Text]) -> int: ... # Unix only TODO +def spawnlpe(mode: int, file: _PathType, arg0: Union[bytes, Text], *args: Any) -> int: ... # Imprecise signature; Unix only TODO def spawnv(mode: int, path: _PathType, args: List[Union[bytes, Text]]) -> int: ... def spawnve(mode: int, path: _PathType, args: List[Union[bytes, Text]], From b362177cc424a2cd707809ce60853a954f77a6e7 Mon Sep 17 00:00:00 2001 From: David Euresti Date: Mon, 20 Mar 2017 22:36:44 -0700 Subject: [PATCH 5/5] Fix typo --- stdlib/2/os/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/2/os/__init__.pyi b/stdlib/2/os/__init__.pyi index 9c4c91444..f96aae352 100644 --- a/stdlib/2/os/__init__.pyi +++ b/stdlib/2/os/__init__.pyi @@ -194,7 +194,7 @@ def unlink(path: _PathType) -> None: ... def utime(path: _PathType, times: Optional[Tuple[int, int]]) -> None: ... def walk(top: AnyStr, topdown: bool = ..., onerror: Any = ..., followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], - List[Anystr]]]: ... + List[AnyStr]]]: ... def abort() -> None: ... def execl(file: _PathType, *args) -> None: ...