mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-10 13:32:26 +08:00
apply black and isort (#4287)
* apply black and isort * move some type ignores
This commit is contained in:
@@ -1,12 +1,32 @@
|
||||
import sys
|
||||
from builtins import OSError as error
|
||||
from io import TextIOWrapper as _TextIOWrapper
|
||||
from posix import listdir as listdir, stat_result as stat_result # TODO: use this, see https://github.com/python/mypy/issues/3078
|
||||
import sys
|
||||
from typing import (
|
||||
Mapping, MutableMapping, Dict, List, Any, Tuple, Iterator, overload, Union, AnyStr,
|
||||
Optional, Generic, Set, Callable, Text, Sequence, IO, NamedTuple, NoReturn, TypeVar
|
||||
IO,
|
||||
Any,
|
||||
AnyStr,
|
||||
Callable,
|
||||
Dict,
|
||||
Generic,
|
||||
Iterator,
|
||||
List,
|
||||
Mapping,
|
||||
MutableMapping,
|
||||
NamedTuple,
|
||||
NoReturn,
|
||||
Optional,
|
||||
Sequence,
|
||||
Set,
|
||||
Text,
|
||||
Tuple,
|
||||
TypeVar,
|
||||
Union,
|
||||
overload,
|
||||
)
|
||||
|
||||
from _typeshed import AnyPath
|
||||
|
||||
from . import path as path
|
||||
|
||||
# We need to use something from path, or flake8 and pytype get unhappy
|
||||
@@ -39,32 +59,32 @@ O_TRUNC: int
|
||||
# We don't use sys.platform for O_* flags to denote platform-dependent APIs because some codes,
|
||||
# including tests for mypy, use a more finer way than sys.platform before using these APIs
|
||||
# See https://github.com/python/typeshed/pull/2286 for discussions
|
||||
O_DSYNC: int # Unix only
|
||||
O_RSYNC: int # Unix only
|
||||
O_SYNC: int # Unix only
|
||||
O_NDELAY: int # Unix only
|
||||
O_DSYNC: int # Unix only
|
||||
O_RSYNC: int # Unix only
|
||||
O_SYNC: int # Unix only
|
||||
O_NDELAY: int # Unix only
|
||||
O_NONBLOCK: int # Unix only
|
||||
O_NOCTTY: int # Unix only
|
||||
O_SHLOCK: int # Unix only
|
||||
O_EXLOCK: int # Unix only
|
||||
O_BINARY: int # Windows only
|
||||
O_NOCTTY: int # Unix only
|
||||
O_SHLOCK: int # Unix only
|
||||
O_EXLOCK: int # Unix only
|
||||
O_BINARY: int # Windows only
|
||||
O_NOINHERIT: int # Windows only
|
||||
O_SHORT_LIVED: int # Windows only
|
||||
O_TEMPORARY: int # Windows only
|
||||
O_RANDOM: int # Windows only
|
||||
O_RANDOM: int # Windows only
|
||||
O_SEQUENTIAL: int # Windows only
|
||||
O_TEXT: int # Windows only
|
||||
O_ASYNC: int # Gnu extension if in C library
|
||||
O_DIRECT: int # Gnu extension if in C library
|
||||
O_TEXT: int # Windows only
|
||||
O_ASYNC: int # Gnu extension if in C library
|
||||
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_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
|
||||
sep: str
|
||||
if sys.platform == 'win32':
|
||||
if sys.platform == "win32":
|
||||
altsep: str
|
||||
else:
|
||||
altsep: Optional[str]
|
||||
@@ -92,7 +112,7 @@ environ: _Environ[str]
|
||||
if sys.version_info >= (3, 2):
|
||||
environb: _Environ[bytes]
|
||||
|
||||
if sys.platform != 'win32':
|
||||
if sys.platform != "win32":
|
||||
# Unix only
|
||||
confstr_names: Dict[str, int]
|
||||
pathconf_names: Dict[str, int]
|
||||
@@ -119,12 +139,12 @@ if sys.platform != 'win32':
|
||||
P_NOWAIT: int
|
||||
P_NOWAITO: int
|
||||
P_WAIT: int
|
||||
if sys.platform == 'win32':
|
||||
if sys.platform == "win32":
|
||||
P_DETACH: int
|
||||
P_OVERLAY: int
|
||||
|
||||
# wait()/waitpid() options
|
||||
if sys.platform != 'win32':
|
||||
if sys.platform != "win32":
|
||||
WNOHANG: int # Unix only
|
||||
WCONTINUED: int # some Unix systems
|
||||
WUNTRACED: int # Unix only
|
||||
@@ -153,7 +173,7 @@ def getppid() -> int: ...
|
||||
def strerror(code: int) -> str: ...
|
||||
def umask(mask: int) -> int: ...
|
||||
|
||||
if sys.platform != 'win32':
|
||||
if sys.platform != "win32":
|
||||
def ctermid() -> str: ...
|
||||
def getegid() -> int: ...
|
||||
def geteuid() -> int: ...
|
||||
@@ -186,7 +206,6 @@ def getenv(key: Text) -> Optional[str]: ...
|
||||
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: ...
|
||||
@@ -226,17 +245,19 @@ def stat_float_times() -> bool: ...
|
||||
def stat_float_times(newvalue: bool) -> None: ...
|
||||
def symlink(source: AnyPath, link_name: AnyPath) -> None: ...
|
||||
def unlink(path: AnyPath) -> None: ...
|
||||
|
||||
# TODO: add ns, dir_fd, follow_symlinks argument
|
||||
if sys.version_info >= (3, 0):
|
||||
def utime(path: AnyPath, times: Optional[Tuple[float, float]] = ...) -> None: ...
|
||||
|
||||
else:
|
||||
def utime(path: AnyPath, times: Optional[Tuple[float, float]]) -> None: ...
|
||||
|
||||
if sys.platform != 'win32':
|
||||
if sys.platform != "win32":
|
||||
# Unix only
|
||||
def fchmod(fd: int, mode: int) -> None: ...
|
||||
def fchown(fd: int, uid: int, gid: int) -> None: ...
|
||||
if sys.platform != 'darwin':
|
||||
if sys.platform != "darwin":
|
||||
def fdatasync(fd: int) -> None: ... # Unix only, not Mac
|
||||
def fpathconf(fd: int, name: Union[str, int]) -> int: ...
|
||||
def fstatvfs(fd: int) -> _StatVFS: ...
|
||||
@@ -257,16 +278,20 @@ if sys.platform != 'win32':
|
||||
def statvfs(path: AnyPath) -> _StatVFS: ...
|
||||
|
||||
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]]]: ...
|
||||
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 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.
|
||||
def execl(file: AnyPath, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ...
|
||||
def execlp(file: AnyPath, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ...
|
||||
@@ -278,15 +303,15 @@ def execlpe(file: AnyPath, __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.
|
||||
_ExecVArgs = Union[Tuple[Union[bytes, Text], ...], List[bytes], List[Text], List[Union[bytes, Text]]]
|
||||
|
||||
def execv(path: AnyPath, args: _ExecVArgs) -> NoReturn: ...
|
||||
def execve(path: AnyPath, args: _ExecVArgs, env: Mapping[str, str]) -> NoReturn: ...
|
||||
def execvp(file: AnyPath, args: _ExecVArgs) -> NoReturn: ...
|
||||
def execvpe(file: AnyPath, args: _ExecVArgs, env: Mapping[str, str]) -> NoReturn: ...
|
||||
|
||||
def _exit(n: int) -> NoReturn: ...
|
||||
def kill(pid: int, sig: int) -> None: ...
|
||||
|
||||
if sys.platform != 'win32':
|
||||
if sys.platform != "win32":
|
||||
# Unix only
|
||||
def fork() -> int: ...
|
||||
def forkpty() -> Tuple[int, int]: ... # some flavors of Unix
|
||||
@@ -297,9 +322,9 @@ if sys.platform != 'win32':
|
||||
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 __init__(self, command: str, mode: str = ..., bufsize: int = ...) -> None: ...
|
||||
def close(self) -> Any: ... # may return int
|
||||
|
||||
else:
|
||||
def popen(command: str, *args, **kwargs) -> IO[Any]: ...
|
||||
def popen2(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any]]: ...
|
||||
@@ -307,18 +332,17 @@ else:
|
||||
def popen4(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any]]: ...
|
||||
|
||||
def spawnl(mode: int, path: AnyPath, arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> int: ...
|
||||
def spawnle(mode: int, path: AnyPath, arg0: Union[bytes, Text],
|
||||
*args: Any) -> int: ... # Imprecise sig
|
||||
def spawnle(mode: int, path: AnyPath, arg0: Union[bytes, Text], *args: Any) -> int: ... # Imprecise sig
|
||||
def spawnv(mode: int, path: AnyPath, args: List[Union[bytes, Text]]) -> int: ...
|
||||
def spawnve(mode: int, path: AnyPath, args: List[Union[bytes, Text]],
|
||||
env: Mapping[str, str]) -> int: ...
|
||||
def spawnve(mode: int, path: AnyPath, args: List[Union[bytes, Text]], env: Mapping[str, str]) -> int: ...
|
||||
def system(command: AnyPath) -> int: ...
|
||||
def times() -> Tuple[float, float, float, float, float]: ...
|
||||
def waitpid(pid: int, options: int) -> Tuple[int, int]: ...
|
||||
def urandom(n: int) -> bytes: ...
|
||||
|
||||
if sys.platform == 'win32':
|
||||
if sys.platform == "win32":
|
||||
def startfile(path: AnyPath, operation: Optional[str] = ...) -> None: ...
|
||||
|
||||
else:
|
||||
# Unix only
|
||||
def spawnlp(mode: int, file: AnyPath, arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> int: ...
|
||||
@@ -342,6 +366,7 @@ else:
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
def sched_getaffinity(id: int) -> Set[int]: ...
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
class waitresult:
|
||||
si_pid: int
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent!
|
||||
import os
|
||||
import sys
|
||||
from typing import overload, List, Any, AnyStr, Sequence, Tuple, TypeVar, Text, Callable, Optional
|
||||
from genericpath import exists as exists
|
||||
from _typeshed import StrPath, BytesPath, AnyPath
|
||||
from typing import Any, AnyStr, Callable, List, Optional, Sequence, Text, Tuple, TypeVar, overload
|
||||
|
||||
_T = TypeVar('_T')
|
||||
from _typeshed import AnyPath, BytesPath, StrPath
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
if sys.version_info >= (3, 6):
|
||||
from builtins import _PathLike
|
||||
@@ -16,7 +17,7 @@ supports_unicode_filenames: bool
|
||||
curdir: str
|
||||
pardir: str
|
||||
sep: str
|
||||
if sys.platform == 'win32':
|
||||
if sys.platform == "win32":
|
||||
altsep: str
|
||||
else:
|
||||
altsep: Optional[str]
|
||||
@@ -56,7 +57,7 @@ if sys.version_info >= (3, 6):
|
||||
def normpath(path: _PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def normpath(path: AnyStr) -> AnyStr: ...
|
||||
if sys.platform == 'win32':
|
||||
if sys.platform == "win32":
|
||||
@overload
|
||||
def realpath(path: _PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
@@ -75,7 +76,7 @@ else:
|
||||
def expandvars(path: AnyStr) -> AnyStr: ...
|
||||
def normcase(s: AnyStr) -> AnyStr: ...
|
||||
def normpath(path: AnyStr) -> AnyStr: ...
|
||||
if sys.platform == 'win32':
|
||||
if sys.platform == "win32":
|
||||
def realpath(path: AnyStr) -> AnyStr: ...
|
||||
else:
|
||||
def realpath(filename: AnyStr) -> AnyStr: ...
|
||||
@@ -84,6 +85,7 @@ if sys.version_info >= (3, 6):
|
||||
# In reality it returns str for sequences of StrPath and bytes for sequences
|
||||
# of BytesPath, but mypy does not accept such a signature.
|
||||
def commonpath(paths: Sequence[AnyPath]) -> Any: ...
|
||||
|
||||
elif sys.version_info >= (3, 5):
|
||||
def commonpath(paths: Sequence[AnyStr]) -> AnyStr: ...
|
||||
|
||||
@@ -91,7 +93,6 @@ elif sys.version_info >= (3, 5):
|
||||
# Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes
|
||||
# So, fall back to Any
|
||||
def commonprefix(m: Sequence[AnyPath]) -> Any: ...
|
||||
|
||||
def lexists(path: AnyPath) -> bool: ...
|
||||
|
||||
# These return float if os.stat_float_times() == True,
|
||||
@@ -99,7 +100,6 @@ def lexists(path: AnyPath) -> bool: ...
|
||||
def getatime(filename: AnyPath) -> float: ...
|
||||
def getmtime(filename: AnyPath) -> float: ...
|
||||
def getctime(filename: AnyPath) -> float: ...
|
||||
|
||||
def getsize(filename: AnyPath) -> int: ...
|
||||
def isabs(s: AnyPath) -> bool: ...
|
||||
def isfile(path: AnyPath) -> bool: ...
|
||||
@@ -122,11 +122,13 @@ if sys.version_info < (3, 0):
|
||||
def join(__p1: bytes, __p2: Text, *p: AnyPath) -> Text: ...
|
||||
@overload
|
||||
def join(__p1: Text, *p: AnyPath) -> Text: ...
|
||||
|
||||
elif sys.version_info >= (3, 6):
|
||||
@overload
|
||||
def join(a: StrPath, *paths: StrPath) -> Text: ...
|
||||
@overload
|
||||
def join(a: BytesPath, *paths: BytesPath) -> bytes: ...
|
||||
|
||||
else:
|
||||
def join(a: AnyStr, *paths: AnyStr) -> AnyStr: ...
|
||||
|
||||
@@ -134,7 +136,6 @@ else:
|
||||
def relpath(path: BytesPath, start: Optional[BytesPath] = ...) -> bytes: ...
|
||||
@overload
|
||||
def relpath(path: StrPath, start: Optional[StrPath] = ...) -> Text: ...
|
||||
|
||||
def samefile(f1: AnyPath, f2: AnyPath) -> bool: ...
|
||||
def sameopenfile(fp1: int, fp2: int) -> bool: ...
|
||||
def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ...
|
||||
@@ -152,12 +153,13 @@ if sys.version_info >= (3, 6):
|
||||
def splitext(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
|
||||
@overload
|
||||
def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
|
||||
|
||||
else:
|
||||
def split(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
|
||||
def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
|
||||
def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
|
||||
|
||||
if sys.version_info < (3, 7) and sys.platform == 'win32':
|
||||
if sys.version_info < (3, 7) and sys.platform == "win32":
|
||||
def splitunc(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated
|
||||
|
||||
if sys.version_info < (3,):
|
||||
|
||||
Reference in New Issue
Block a user