Fix some type errors in os module. (#1101)

* Fix some type errors in os module.

Found these because they were different between Python 2 and 3.

* Code Review changes

* Make it __arg0
This commit is contained in:
David Euresti
2017-03-26 16:39:07 -07:00
committed by Jelle Zijlstra
parent 1cc3489463
commit ec83ed90eb
2 changed files with 45 additions and 39 deletions

View File

@@ -1,8 +1,8 @@
# created from https://docs.python.org/2/library/os.html
from typing import (
List, Tuple, Union, Sequence, Mapping, IO, Any, Optional, AnyStr, Iterator,
Dict, MutableMapping, NamedTuple, overload, Text
Mapping, MutableMapping, Dict, List, Any, Tuple, Iterator, overload, Union, AnyStr,
Optional, Generic, Set, Callable, Text, Sequence, IO, NamedTuple
)
from . import path
from mypy_extensions import NoReturn
@@ -118,7 +118,7 @@ def setegid(egid: int) -> None: ... # Unix only
def seteuid(euid: int) -> None: ... # Unix only
def setgid(gid: int) -> None: ... # Unix only
def setgroups(groups: Sequence[int]) -> None: ... # Unix only
def setpgrp(*args) -> None: ... # Unix only
def setpgrp() -> None: ... # Unix only
def setpgid(pid: int, pgrp: int) -> None: ... # Unix only
def setregid(rgid: int, egid: int) -> None: ... # Unix only
def setresgid(rgid: int, egid: int, sgid: int) -> None: ... # Unix only
@@ -126,7 +126,7 @@ def setresuid(ruid: int, euid: int, suid: int) -> None: ... # Unix only
def setreuid(ruid: int, euid: int) -> None: ... # Unix only
def getsid(pid: int) -> int: ... # Unix only
def setsid() -> None: ... # Unix only
def setuid(pid: int) -> None: ... # Unix only
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
@@ -139,21 +139,21 @@ def dup2(fd: int, fd2: int) -> None: ...
def fchmod(fd: int, mode: int) -> None: ... # Unix only
def fchown(fd: int, uid: int, gid: int) -> None: ... # Unix only
def fdatasync(fd: int) -> None: ... # Unix only, not Mac
def fpathconf(fd: int, name: str) -> None: ... # Unix only
def fpathconf(fd: int, name: Union[str, int]) -> int: ... # Unix only
def fstat(fd: int) -> Any: ...
def fstatvfs(fd: int) -> _StatVFS: ... # Unix only
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) -> None: ...
def lseek(fd: int, pos: int, how: 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) -> str: ...
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, str: str) -> int: ...
def write(fd: int, string: bytes) -> int: ...
def access(path: _PathType, mode: int) -> bool: ...
def chdir(path: _PathType) -> None: ...
def fchdir(fd: int) -> None: ...
@@ -164,9 +164,9 @@ 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, uid: int, gid: 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(source: _PathType, link_name: _PathType) -> None: ...
def link(src: _PathType, link_name: _PathType) -> None: ...
def listdir(path: AnyStr) -> List[AnyStr]: ...
def lstat(path: _PathType) -> Any: ...
def mkfifo(path: _PathType, mode: int = ...) -> None: ... # Unix only
@@ -176,7 +176,7 @@ def minor(device: int) -> int: ...
def makedev(major: int, minor: int) -> int: ...
def mkdir(path: _PathType, mode: int = ...) -> None: ...
def makedirs(path: _PathType, mode: int = ...) -> None: ...
def pathconf(path: _PathType, name: str) -> str: ... # Unix only
def pathconf(path: _PathType, name: Union[str, int]) -> int: ... # Unix only
def readlink(path: AnyStr) -> AnyStr: ...
def remove(path: _PathType) -> None: ...
def removedirs(path: _PathType) -> None: ...
@@ -191,16 +191,21 @@ def stat_float_times() -> bool: ...
def statvfs(path: _PathType) -> _StatVFS: ... # Unix only
def symlink(source: _PathType, link_name: _PathType) -> None: ...
def unlink(path: _PathType) -> None: ...
def utime(path: _PathType, times: Optional[Tuple[int, int]]) -> None: ...
def utime(path: _PathType, times: Optional[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(file: _PathType, *args) -> None: ...
def execle(file: _PathType, *args) -> None: ...
def execlp(file: _PathType, *args) -> None: ...
def execlpe(file: _PathType, *args) -> None: ...
def abort() -> NoReturn: ...
# These are defined as execl(file, *args) but the first *arg is mandatory.
def execl(file: _PathType, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ...
def execlp(file: _PathType, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ...
# These are: execle(file, *args, env) but env is pulled from the last element of the args.
def execle(file: _PathType, __arg0: Union[bytes, Text], *args: Any) -> NoReturn: ...
def execlpe(file: _PathType, __arg0: Union[bytes, Text], *args: Any) -> NoReturn: ...
# The docs say `args: tuple or list of strings`
# The implementation enforces tuple or list so we can't use Sequence.
@@ -254,7 +259,7 @@ def WTERMSIG(status: int) -> int: ... # Unix only
def confstr(name: Union[str, int]) -> Optional[str]: ... # Unix only
def getloadavg() -> Tuple[float, float, float]: ... # Unix only
def sysconf(name: Union[str, int]) -> int: ... # Unix only
def urandom(n: int) -> str: ...
def urandom(n: int) -> bytes: ...
def tmpfile() -> IO[Any]: ...
def tmpnam() -> str: ...

View File

@@ -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, Text
Optional, Generic, Set, Callable, Text, Sequence
)
from . import path
from mypy_extensions import NoReturn
@@ -243,15 +243,15 @@ def putenv(key: AnyStr, value: AnyStr) -> None: ...
def setegid(egid: int) -> None: ... # Unix only
def seteuid(euid: int) -> None: ... # Unix only
def setgid(gid: int) -> None: ... # Unix only
def setgroups(groups: List[int]) -> None: ... # Unix only
def setpgrp() -> int: ... # Unix only
def setpgid(pid: int, pgrp: int) -> int: ... # Unix only
def setgroups(groups: Sequence[int]) -> None: ... # Unix only
def setpgrp() -> None: ... # Unix only
def setpgid(pid: int, pgrp: int) -> None: ... # Unix only
def setregid(rgid: int, egid: int) -> None: ... # Unix only
def setresgid(rgid: int, egid: int, sgid: int) -> None: ... # Unix only
def setresuid(ruid: int, euid: int, suid: int) -> None: ... # Unix only
def setreuid(ruid: int, euid: int) -> None: ... # Unix only
def getsid(pid: int) -> int: ... # Unix only
def setsid() -> int: ... # Unix only
def setsid() -> None: ... # Unix only
def setuid(uid: int) -> None: ... # Unix only
def strerror(code: int) -> str: ...
def umask(mask: int) -> int: ...
@@ -268,7 +268,7 @@ def dup2(fd: int, fd2: int) -> None: ...
def fchmod(fd: int, mode: int) -> None: ... # Unix only
def fchown(fd: int, uid: int, gid: int) -> None: ... # Unix only
def fdatasync(fd: int) -> None: ... # Unix only, not Mac
def fpathconf(fd: int, name: str) -> int: ... # Unix only
def fpathconf(fd: int, name: Union[str, int]) -> int: ... # Unix only
def fstat(fd: int) -> stat_result: ...
def fstatvfs(fd: int) -> statvfs_result: ... # Unix only
def fsync(fd: int) -> None: ...
@@ -311,7 +311,7 @@ def makedev(major: int, minor: int) -> int: ...
def mkdir(path: _PathType, mode: int = ...) -> None: ...
def makedirs(path: _PathType, mode: int = ...,
exist_ok: bool = ...) -> None: ...
def pathconf(path: _PathType, name: str) -> int: ... # Unix only
def pathconf(path: _PathType, name: Union[str, int]) -> int: ... # Unix only
def readlink(path: AnyStr) -> AnyStr: ...
def remove(path: _PathType) -> None: ...
def removedirs(path: _PathType) -> None: ...
@@ -332,20 +332,21 @@ def symlink(source: _PathType, link_name: _PathType,
target_is_directory: bool = ...) -> None:
... # final argument in Windows only
def unlink(path: _PathType) -> None: ...
def utime(path: _PathType, times: Union[Tuple[int, int], Tuple[float, float]] = ...) -> None: ...
def utime(path: _PathType, times: Optional[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: _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: Union[bytes, Text], *args: Union[bytes, Text]) -> None: ...
def execlpe(path: _PathType, arg0: Union[bytes, Text],
*args: Any) -> None: ... # Imprecise signature
def abort() -> NoReturn: ...
# These are defined as execl(file, *args) but the first *arg is mandatory.
def execl(file: _PathType, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ...
def execlp(file: _PathType, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ...
# These are: execle(file, *args, env) but env is pulled from the last element of the args.
def execle(file: _PathType, __arg0: Union[bytes, Text], *args: Any) -> NoReturn: ...
def execlpe(file: _PathType, __arg0: Union[bytes, Text], *args: Any) -> NoReturn: ...
# The docs say `args: tuple or list of strings`
# The implementation enforces tuple or list so we can't use Sequence.
@@ -388,19 +389,19 @@ 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]: ...
def wait3(options: Union[int, None] = ...) -> Tuple[int, int, Any]: ... # Unix only
def wait3(options: int) -> Tuple[int, int, Any]: ... # Unix only
def wait4(pid: int, options: int) -> Tuple[int, int, Any]: ... # Unix only
def WCOREDUMP(status: int) -> bool: ... # Unix only
def WIFCONTINUED(status: int) -> bool: ... # Unix only
def WIFSTOPPED(status: int) -> bool: ... # Unix only
def WIFSIGNALED(status: int) -> bool: ... # Unix only
def WIFEXITED(status: int) -> bool: ... # Unix only
def WEXITSTATUS(status: int) -> bool: ... # Unix only
def WSTOPSIG(status: int) -> bool: ... # Unix only
def WTERMSIG(status: int) -> bool: ... # Unix only
def confstr(name: str) -> str: ... # Unix only
def WEXITSTATUS(status: int) -> int: ... # Unix only
def WSTOPSIG(status: int) -> int: ... # Unix only
def WTERMSIG(status: int) -> int: ... # Unix only
def confstr(name: Union[str, int]) -> Optional[str]: ... # Unix only
def getloadavg() -> Tuple[float, float, float]: ... # Unix only
def sysconf(name: str) -> int: ... # Unix only
def sysconf(name: Union[str, int]) -> int: ... # Unix only
def urandom(n: int) -> bytes: ...
def sched_getaffinity(id: int) -> Set[int]: ...