mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-06 20:24:30 +08:00
Fix os.getenv and friends to have consistent types (#1131)
This commit is contained in:
committed by
Jelle Zijlstra
parent
8d3c6b14f6
commit
b03e79886e
@@ -1,13 +1,16 @@
|
||||
# created from https://docs.python.org/2/library/os.html
|
||||
|
||||
from builtins import OSError as error
|
||||
import sys
|
||||
from typing import (
|
||||
Mapping, MutableMapping, Dict, List, Any, Tuple, Iterator, overload, Union, AnyStr,
|
||||
Optional, Generic, Set, Callable, Text, Sequence, IO, NamedTuple
|
||||
Optional, Generic, Set, Callable, Text, Sequence, IO, NamedTuple, TypeVar
|
||||
)
|
||||
from . import path
|
||||
from . import path as path
|
||||
from mypy_extensions import NoReturn
|
||||
|
||||
error = OSError
|
||||
_T = TypeVar('_T')
|
||||
|
||||
SEEK_SET = 0
|
||||
SEEK_CUR = 0
|
||||
SEEK_END = 0
|
||||
@@ -58,13 +61,15 @@ R_OK = 0
|
||||
W_OK = 0
|
||||
X_OK = 0
|
||||
|
||||
class _Environ(MutableMapping[str, str]):
|
||||
def copy(self) -> Dict[str, str]: ...
|
||||
class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]):
|
||||
def copy(self) -> Dict[AnyStr, AnyStr]: ...
|
||||
|
||||
environ = ... # type: _Environ[str]
|
||||
|
||||
confstr_names = ... # type: Dict[str, int] # Unix only
|
||||
pathconf_names = ... # type: Dict[str, int] # Unix only
|
||||
sysconf_names = ... # type: Dict[str, int] # Unix only
|
||||
|
||||
environ = ... # type: _Environ
|
||||
confstr_names = ... # type: Mapping[str, int] # Unix only
|
||||
pathconf_names = ... # type: Mapping[str, int] # Unix only
|
||||
sysconf_names = ... # type: Mapping[str, int] # Unix only
|
||||
EX_OK = 0 # Unix only
|
||||
EX_USAGE = 0 # Unix only
|
||||
EX_DATAERR = 0 # Unix only
|
||||
@@ -112,8 +117,6 @@ def getppid() -> int: ...
|
||||
def getresuid() -> Tuple[int, int, int]: ... # Unix only
|
||||
def getresgid() -> Tuple[int, int, int]: ... # Unix only
|
||||
def getuid() -> int: ... # Unix only
|
||||
def getenv(varname: unicode, value: unicode = ...) -> str: ...
|
||||
def putenv(varname: unicode, value: unicode) -> None: ...
|
||||
def setegid(egid: int) -> None: ... # Unix only
|
||||
def seteuid(euid: int) -> None: ... # Unix only
|
||||
def setgid(gid: int) -> None: ... # Unix only
|
||||
@@ -130,7 +133,14 @@ 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(varname: str) -> None: ...
|
||||
|
||||
@overload
|
||||
def getenv(key: Text) -> Optional[str]: ...
|
||||
@overload
|
||||
def getenv(key: Text, default: _T) -> Union[str, _T]: ...
|
||||
def putenv(key: Union[bytes, Text], value: Union[bytes, Text]) -> None: ...
|
||||
def unsetenv(key: Union[bytes, Text]) -> None: ...
|
||||
|
||||
def fdopen(fd: int, *args, **kwargs) -> IO[Any]: ...
|
||||
def close(fd: int) -> None: ...
|
||||
def closerange(fd_low: int, fd_high: int) -> None: ...
|
||||
|
||||
@@ -8,11 +8,13 @@ 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
|
||||
Optional, Generic, Set, Callable, Text, Sequence, NamedTuple, TypeVar
|
||||
)
|
||||
from . import path
|
||||
from . import path as path
|
||||
from mypy_extensions import NoReturn
|
||||
|
||||
_T = TypeVar('_T')
|
||||
|
||||
# ----- os variables -----
|
||||
|
||||
supports_bytes_environ = False # TODO: True when bytes implemented?
|
||||
@@ -236,10 +238,6 @@ def getppid() -> int: ...
|
||||
def getresuid() -> Tuple[int, int, int]: ... # Unix only
|
||||
def getresgid() -> Tuple[int, int, int]: ... # Unix only
|
||||
def getuid() -> int: ... # Unix only
|
||||
def getenv(key: str, default: str = ...) -> str: ...
|
||||
def getenvb(key: bytes, default: bytes = ...) -> bytes: ...
|
||||
# TODO mixed str/bytes putenv arguments
|
||||
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
|
||||
@@ -256,7 +254,15 @@ 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: _PathType) -> None: ...
|
||||
|
||||
@overload
|
||||
def getenv(key: Text) -> Optional[str]: ...
|
||||
@overload
|
||||
def getenv(key: Text, default: _T) -> Union[str, _T]: ...
|
||||
def getenvb(key: bytes, default: bytes = ...) -> bytes: ...
|
||||
def putenv(key: Union[bytes, Text], value: Union[bytes, Text]) -> None: ...
|
||||
def unsetenv(key: Union[bytes, Text]) -> None: ...
|
||||
|
||||
# Return IO or TextIO
|
||||
def fdopen(fd: int, mode: str = ..., buffering: int = ..., encoding: str = ...,
|
||||
errors: str = ..., newline: str = ..., closefd: bool = ...) -> Any: ...
|
||||
|
||||
Reference in New Issue
Block a user