Skip to content

os: merge the top and bottom of os/__init__.pyi #1458

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 2 commits into from
Jul 5, 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: 79 additions & 16 deletions stdlib/2/os/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# created from https://docs.python.org/2/library/os.html
# Stubs for os
# Ron Murawski <[email protected]>

from builtins import OSError as error
from io import TextIOWrapper as _TextIOWrapper
import sys
from typing import (
Mapping, MutableMapping, Dict, List, Any, Tuple, Iterator, overload, Union, AnyStr,
Expand All @@ -11,11 +13,21 @@ from mypy_extensions import NoReturn

_T = TypeVar('_T')

# ----- os variables -----

if sys.version_info >= (3, 2):
supports_bytes_environ: bool

if sys.version_info >= (3, 3):
supports_dir_fd: Set[Callable[..., Any]]
supports_fd: Set[Callable[..., Any]]
supports_effective_ids: Set[Callable[..., Any]]
supports_follow_symlinks: Set[Callable[..., Any]]

SEEK_SET: int
SEEK_CUR: int
SEEK_END: int

# More constants, copied from stdlib/3/os/__init__.pyi
O_RDONLY: int
O_WRONLY: int
O_RDWR: int
Expand Down Expand Up @@ -65,6 +77,8 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]):
def copy(self) -> Dict[AnyStr, AnyStr]: ...

environ: _Environ[str]
if sys.version_info >= (3, 2):
environb: _Environ[bytes]

confstr_names: Dict[str, int] # Unix only
pathconf_names: Dict[str, int] # Unix only
Expand All @@ -86,6 +100,8 @@ EX_TEMPFAIL: int # Unix only
EX_PROTOCOL: int # Unix only
EX_NOPERM: int # Unix only
EX_CONFIG: int # Unix only
EX_NOTFOUND: int # Unix only

P_NOWAIT: int
P_NOWAITO: int
P_WAIT: int
Expand All @@ -99,7 +115,13 @@ WCONTINUED: int # some Unix systems
WUNTRACED: int # Unix only

TMP_MAX: int # Undocumented, but used by tempfile
_PathType = Union[bytes, Text]

# ----- os classes (structures) -----
if sys.version_info >= (3, 6):
from builtins import _PathLike as PathLike # See comment in builtins

_PathType = path._PathType

_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 @@ -202,12 +224,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[float, float]]) -> None: ...
# TODO: add ns, dir_fd, follow_symlinks argument
if sys.version_info >= (3, 0):
def utime(path: _PathType, times: Optional[Tuple[float, float]] = ...) -> None: ...
else:
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]]]: ...
if sys.version_info >= (3, 6):
def walk(top: Union[AnyStr, PathLike[AnyStr]], topdown: bool = ...,
onerror: Optional[Callable[[OSError], Any]] = ...,
followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr],
List[AnyStr]]]: ...
else:
def walk(top: AnyStr, topdown: bool = ..., onerror: Optional[Callable[[OSError], Any]] = ...,
followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr],
List[AnyStr]]]: ...

def abort() -> NoReturn: ...
# These are defined as execl(file, *args) but the first *arg is mandatory.
Expand All @@ -232,11 +263,19 @@ def forkpty() -> Tuple[int, int]: ... # some flavors of Unix
def kill(pid: int, sig: int) -> None: ...
def killpg(pgid: int, sig: int) -> None: ... # Unix only
def nice(increment: int) -> int: ... # Unix only
# TODO: plock, popen*, P_*
def popen(command: str, *args, **kwargs) -> Optional[IO[Any]]: ...
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 plock(op: int) -> None: ... # Unix only ???op is int?

if sys.version_info >= (3, 0):
class popen(_TextIOWrapper):
# TODO 'b' modes or bytes command not accepted?
def __init__(self, command: str, mode: str = ...,
bufsize: int = ...) -> None: ...
def close(self) -> Any: ... # may return int
else:
def popen(command: str, *args, **kwargs) -> Optional[IO[Any]]: ...
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: Union[bytes, Text], *args: Union[bytes, Text]) -> int: ...
def spawnle(mode: int, path: _PathType, arg0: Union[bytes, Text],
Expand Down Expand Up @@ -272,10 +311,34 @@ def getloadavg() -> Tuple[float, float, float]: ... # Unix only
def sysconf(name: Union[str, int]) -> int: ... # Unix only
def urandom(n: int) -> bytes: ...

def tmpfile() -> IO[Any]: ...
def tmpnam() -> str: ...
def tempnam(dir: str = ..., prefix: str = ...) -> str: ...
if sys.version_info >= (3, 0):
def sched_getaffinity(id: int) -> Set[int]: ...
if sys.version_info >= (3, 3):
class waitresult:
si_pid: int
def waitid(idtype: int, id: int, options: int) -> waitresult: ...

if sys.version_info < (3, 0):
def tmpfile() -> IO[Any]: ...
def tmpnam() -> str: ...
def tempnam(dir: str = ..., prefix: str = ...) -> str: ...

P_ALL: int
WEXITED: int
WNOWAIT: int

if sys.version_info >= (3, 3):
def sync() -> None: ... # Unix only

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 = ...,
dir_fd: int = ...) -> Iterator[Tuple[AnyStr, List[AnyStr],
List[AnyStr], int]]: ... # Unix only

terminal_size = NamedTuple('terminal_size', [('columns', int), ('lines', int)])
def get_terminal_size(fd: int = ...) -> terminal_size: ...

if sys.version_info >= (3, 4):
def cpu_count() -> Optional[int]: ...
49 changes: 34 additions & 15 deletions stdlib/3/os/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Stubs for os
# Ron Murawski <[email protected]>

# based on http: //docs.python.org/3.2/library/os.html

from builtins import OSError as error
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, Sequence, NamedTuple, TypeVar
Optional, Generic, Set, Callable, Text, Sequence, IO, NamedTuple, TypeVar
)
from . import path as path
from mypy_extensions import NoReturn
Expand All @@ -17,7 +15,8 @@ _T = TypeVar('_T')

# ----- os variables -----

supports_bytes_environ: bool
if sys.version_info >= (3, 2):
supports_bytes_environ: bool

if sys.version_info >= (3, 3):
supports_dir_fd: Set[Callable[..., Any]]
Expand Down Expand Up @@ -56,6 +55,7 @@ O_DIRECT: int # Gnu extension if in C library
O_DIRECTORY: int # Gnu extension if in C library
O_NOFOLLOW: int # Gnu extension if in C library
O_NOATIME: int # Gnu extension if in C library
O_LARGEFILE: int # Gnu extension if in C library

curdir: str
pardir: str
Expand All @@ -77,7 +77,8 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]):
def copy(self) -> Dict[AnyStr, AnyStr]: ...

environ: _Environ[str]
environb: _Environ[bytes]
if sys.version_info >= (3, 2):
environb: _Environ[bytes]

confstr_names: Dict[str, int] # Unix only
pathconf_names: Dict[str, int] # Unix only
Expand Down Expand Up @@ -346,7 +347,11 @@ 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: Optional[Tuple[float, float]] = ...) -> None: ...
# TODO: add ns, dir_fd, follow_symlinks argument
if sys.version_info >= (3, 0):
def utime(path: _PathType, times: Optional[Tuple[float, float]] = ...) -> None: ...
else:
def utime(path: _PathType, times: Optional[Tuple[float, float]]) -> None: ...

if sys.version_info >= (3, 6):
def walk(top: Union[AnyStr, PathLike[AnyStr]], topdown: bool = ...,
Expand Down Expand Up @@ -383,11 +388,17 @@ def killpg(pgid: int, sig: int) -> None: ... # Unix only
def nice(increment: int) -> int: ... # Unix only
def plock(op: int) -> None: ... # Unix only ???op is int?

class popen(_TextIOWrapper):
# TODO 'b' modes or bytes command not accepted?
def __init__(self, command: str, mode: str = ...,
bufsize: int = ...) -> None: ...
def close(self) -> Any: ... # may return int
if sys.version_info >= (3, 0):
class popen(_TextIOWrapper):
# TODO 'b' modes or bytes command not accepted?
def __init__(self, command: str, mode: str = ...,
bufsize: int = ...) -> None: ...
def close(self) -> Any: ... # may return int
else:
def popen(command: str, *args, **kwargs) -> Optional[IO[Any]]: ...
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: Union[bytes, Text], *args: Union[bytes, Text]) -> int: ...
def spawnle(mode: int, path: _PathType, arg0: Union[bytes, Text],
Expand Down Expand Up @@ -423,10 +434,18 @@ def getloadavg() -> Tuple[float, float, float]: ... # Unix only
def sysconf(name: Union[str, int]) -> int: ... # Unix only
def urandom(n: int) -> bytes: ...

def sched_getaffinity(id: int) -> Set[int]: ...
class waitresult:
si_pid: int
def waitid(idtype: int, id: int, options: int) -> waitresult: ...
if sys.version_info >= (3, 0):
def sched_getaffinity(id: int) -> Set[int]: ...
if sys.version_info >= (3, 3):
class waitresult:
si_pid: int
def waitid(idtype: int, id: int, options: int) -> waitresult: ...

if sys.version_info < (3, 0):
def tmpfile() -> IO[Any]: ...
def tmpnam() -> str: ...
def tempnam(dir: str = ..., prefix: str = ...) -> str: ...

P_ALL: int
WEXITED: int
WNOWAIT: int
Expand Down