Skip to content

Use Union[bytes, Text] for paths in os.py #1054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 48 additions & 47 deletions stdlib/2/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -144,66 +145,66 @@ 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: ...
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 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: AnyStr, topdown: bool = ..., onerror: Any = ...,
followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr],
List[AnyStr]]]: ...

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[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]: ...
Expand All @@ -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: 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: 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: 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: AnyStr, args: List[AnyStr]) -> int: ...
def spawnve(mode: int, path: AnyStr, args: List[AnyStr],
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: AnyStr, args: List[AnyStr]) -> int: ... # Unix only
def spawnvpe(mode: int, file: AnyStr, args: List[AnyStr],
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: 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]: ...
Expand Down
102 changes: 51 additions & 51 deletions stdlib/3/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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: ...
Expand All @@ -245,82 +246,81 @@ 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: ...
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 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 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: _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
def listdir(path: str = ...) -> List[str]: ...
@overload
def listdir(path: bytes) -> List[bytes]: ...

def lstat(path: AnyStr) -> stat_result: ...
def mkfifo(path: str, mode: int = ...) -> None: ... # Unix only
def mknod(filename: AnyStr, mode: int = ..., device: int = ...) -> None: ...
def lstat(path: _PathType) -> stat_result: ...
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: ...
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 statvfs(path: _PathType) -> statvfs_result: ... # Unix only
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 abort() -> 'None': ...
def execl(path: AnyStr, arg0: AnyStr, *args: AnyStr) -> None: ...
def execle(path: AnyStr, arg0: AnyStr,
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: AnyStr, arg0: AnyStr, *args: AnyStr) -> None: ...
def execlpe(path: AnyStr, arg0: AnyStr,
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: 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[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
Expand All @@ -335,22 +335,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: 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: 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: 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: AnyStr, args: List[AnyStr]) -> int: ...
def spawnve(mode: int, path: AnyStr, args: List[AnyStr],
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: AnyStr, args: List[AnyStr]) -> int: ... # Unix only
def spawnvpe(mode: int, file: AnyStr, args: List[AnyStr],
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: 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]: ...
Expand Down Expand Up @@ -381,7 +381,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 = ...,
Expand Down