mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-31 07:05:24 +08:00
Use new union syntax in rest of stdlib (#5884)
This commit is contained in:
@@ -29,7 +29,6 @@ from typing import (
|
||||
Mapping,
|
||||
MutableMapping,
|
||||
NoReturn,
|
||||
Optional,
|
||||
Protocol,
|
||||
Sequence,
|
||||
Set,
|
||||
@@ -171,7 +170,7 @@ sep: str
|
||||
if sys.platform == "win32":
|
||||
altsep: str
|
||||
else:
|
||||
altsep: Optional[str]
|
||||
altsep: str | None
|
||||
extsep: str
|
||||
pathsep: str
|
||||
defpath: str
|
||||
@@ -337,7 +336,7 @@ if sys.platform != "win32":
|
||||
if sys.version_info >= (3, 7):
|
||||
# f_fsid was added in https://github.com/python/cpython/pull/4571
|
||||
class statvfs_result(_Tuple10Int): # Unix only
|
||||
def __new__(cls, seq: Union[_Tuple10Int, _Tuple11Int], dict: Dict[str, int] = ...) -> statvfs_result: ...
|
||||
def __new__(cls, seq: _Tuple10Int | _Tuple11Int, dict: Dict[str, int] = ...) -> statvfs_result: ...
|
||||
n_fields: int
|
||||
n_sequence_fields: int
|
||||
n_unnamed_fields: int
|
||||
@@ -379,7 +378,7 @@ def fspath(path: str) -> str: ...
|
||||
def fspath(path: bytes) -> bytes: ...
|
||||
@overload
|
||||
def fspath(path: PathLike[AnyStr]) -> AnyStr: ...
|
||||
def get_exec_path(env: Optional[Mapping[str, str]] = ...) -> List[str]: ...
|
||||
def get_exec_path(env: Mapping[str, str] | None = ...) -> List[str]: ...
|
||||
|
||||
# NOTE: get_exec_path(): returns List[bytes] when env not None
|
||||
def getlogin() -> str: ...
|
||||
@@ -423,20 +422,20 @@ if sys.platform != "win32":
|
||||
def uname() -> uname_result: ...
|
||||
|
||||
@overload
|
||||
def getenv(key: str) -> Optional[str]: ...
|
||||
def getenv(key: str) -> str | None: ...
|
||||
@overload
|
||||
def getenv(key: str, default: _T) -> Union[str, _T]: ...
|
||||
def getenv(key: str, default: _T) -> str | _T: ...
|
||||
|
||||
if sys.platform != "win32":
|
||||
@overload
|
||||
def getenvb(key: bytes) -> Optional[bytes]: ...
|
||||
def getenvb(key: bytes) -> bytes | None: ...
|
||||
@overload
|
||||
def getenvb(key: bytes, default: _T) -> Union[bytes, _T]: ...
|
||||
def getenvb(key: bytes, default: _T) -> bytes | _T: ...
|
||||
|
||||
def putenv(__name: Union[bytes, str], __value: Union[bytes, str]) -> None: ...
|
||||
def putenv(__name: bytes | str, __value: bytes | str) -> None: ...
|
||||
|
||||
if sys.platform != "win32":
|
||||
def unsetenv(__name: Union[bytes, str]) -> None: ...
|
||||
def unsetenv(__name: bytes | str) -> None: ...
|
||||
|
||||
_Opener = Callable[[str, int], int]
|
||||
|
||||
@@ -445,11 +444,11 @@ def fdopen(
|
||||
fd: int,
|
||||
mode: OpenTextMode = ...,
|
||||
buffering: int = ...,
|
||||
encoding: Optional[str] = ...,
|
||||
errors: Optional[str] = ...,
|
||||
newline: Optional[str] = ...,
|
||||
encoding: str | None = ...,
|
||||
errors: str | None = ...,
|
||||
newline: str | None = ...,
|
||||
closefd: bool = ...,
|
||||
opener: Optional[_Opener] = ...,
|
||||
opener: _Opener | None = ...,
|
||||
) -> _TextIOWrapper: ...
|
||||
@overload
|
||||
def fdopen(
|
||||
@@ -460,7 +459,7 @@ def fdopen(
|
||||
errors: None = ...,
|
||||
newline: None = ...,
|
||||
closefd: bool = ...,
|
||||
opener: Optional[_Opener] = ...,
|
||||
opener: _Opener | None = ...,
|
||||
) -> FileIO: ...
|
||||
@overload
|
||||
def fdopen(
|
||||
@@ -471,7 +470,7 @@ def fdopen(
|
||||
errors: None = ...,
|
||||
newline: None = ...,
|
||||
closefd: bool = ...,
|
||||
opener: Optional[_Opener] = ...,
|
||||
opener: _Opener | None = ...,
|
||||
) -> BufferedRandom: ...
|
||||
@overload
|
||||
def fdopen(
|
||||
@@ -482,7 +481,7 @@ def fdopen(
|
||||
errors: None = ...,
|
||||
newline: None = ...,
|
||||
closefd: bool = ...,
|
||||
opener: Optional[_Opener] = ...,
|
||||
opener: _Opener | None = ...,
|
||||
) -> BufferedWriter: ...
|
||||
@overload
|
||||
def fdopen(
|
||||
@@ -493,7 +492,7 @@ def fdopen(
|
||||
errors: None = ...,
|
||||
newline: None = ...,
|
||||
closefd: bool = ...,
|
||||
opener: Optional[_Opener] = ...,
|
||||
opener: _Opener | None = ...,
|
||||
) -> BufferedReader: ...
|
||||
@overload
|
||||
def fdopen(
|
||||
@@ -504,22 +503,22 @@ def fdopen(
|
||||
errors: None = ...,
|
||||
newline: None = ...,
|
||||
closefd: bool = ...,
|
||||
opener: Optional[_Opener] = ...,
|
||||
opener: _Opener | None = ...,
|
||||
) -> BinaryIO: ...
|
||||
@overload
|
||||
def fdopen(
|
||||
fd: int,
|
||||
mode: str,
|
||||
buffering: int = ...,
|
||||
encoding: Optional[str] = ...,
|
||||
errors: Optional[str] = ...,
|
||||
newline: Optional[str] = ...,
|
||||
encoding: str | None = ...,
|
||||
errors: str | None = ...,
|
||||
newline: str | None = ...,
|
||||
closefd: bool = ...,
|
||||
opener: Optional[_Opener] = ...,
|
||||
opener: _Opener | None = ...,
|
||||
) -> IO[Any]: ...
|
||||
def close(fd: int) -> None: ...
|
||||
def closerange(__fd_low: int, __fd_high: int) -> None: ...
|
||||
def device_encoding(fd: int) -> Optional[str]: ...
|
||||
def device_encoding(fd: int) -> str | None: ...
|
||||
def dup(__fd: int) -> int: ...
|
||||
|
||||
if sys.version_info >= (3, 7):
|
||||
@@ -531,7 +530,7 @@ else:
|
||||
def fstat(fd: int) -> stat_result: ...
|
||||
def fsync(fd: FileDescriptorLike) -> None: ...
|
||||
def lseek(__fd: int, __position: int, __how: int) -> int: ...
|
||||
def open(path: StrOrBytesPath, flags: int, mode: int = ..., *, dir_fd: Optional[int] = ...) -> int: ...
|
||||
def open(path: StrOrBytesPath, flags: int, mode: int = ..., *, dir_fd: int | None = ...) -> int: ...
|
||||
def pipe() -> Tuple[int, int]: ...
|
||||
def read(__fd: int, __length: int) -> bytes: ...
|
||||
|
||||
@@ -541,7 +540,7 @@ if sys.platform != "win32":
|
||||
def fchown(fd: int, uid: int, gid: int) -> None: ...
|
||||
if sys.platform != "darwin":
|
||||
def fdatasync(fd: FileDescriptorLike) -> None: ... # Unix only, not Mac
|
||||
def fpathconf(__fd: int, __name: Union[str, int]) -> int: ...
|
||||
def fpathconf(__fd: int, __name: str | int) -> int: ...
|
||||
def fstatvfs(__fd: int) -> statvfs_result: ...
|
||||
def ftruncate(__fd: int, __length: int) -> None: ...
|
||||
def get_blocking(__fd: int) -> bool: ...
|
||||
@@ -556,7 +555,7 @@ if sys.platform != "win32":
|
||||
def pread(__fd: int, __length: int, __offset: int) -> bytes: ...
|
||||
def pwrite(__fd: int, __buffer: bytes, __offset: int) -> int: ...
|
||||
@overload
|
||||
def sendfile(out_fd: int, in_fd: int, offset: Optional[int], count: int) -> int: ...
|
||||
def sendfile(out_fd: int, in_fd: int, offset: int | None, count: int) -> int: ...
|
||||
@overload
|
||||
def sendfile(
|
||||
out_fd: int,
|
||||
@@ -586,7 +585,7 @@ if sys.platform != "win32":
|
||||
|
||||
def write(__fd: int, __data: bytes) -> int: ...
|
||||
def access(
|
||||
path: _FdOrAnyPath, mode: int, *, dir_fd: Optional[int] = ..., effective_ids: bool = ..., follow_symlinks: bool = ...
|
||||
path: _FdOrAnyPath, mode: int, *, dir_fd: int | None = ..., effective_ids: bool = ..., follow_symlinks: bool = ...
|
||||
) -> bool: ...
|
||||
def chdir(path: _FdOrAnyPath) -> None: ...
|
||||
|
||||
@@ -595,12 +594,12 @@ if sys.platform != "win32":
|
||||
|
||||
def getcwd() -> str: ...
|
||||
def getcwdb() -> bytes: ...
|
||||
def chmod(path: _FdOrAnyPath, mode: int, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> None: ...
|
||||
def chmod(path: _FdOrAnyPath, mode: int, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> None: ...
|
||||
|
||||
if sys.platform != "win32":
|
||||
def chflags(path: StrOrBytesPath, flags: int, follow_symlinks: bool = ...) -> None: ... # some flavors of Unix
|
||||
def chown(
|
||||
path: _FdOrAnyPath, uid: int, gid: int, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...
|
||||
path: _FdOrAnyPath, uid: int, gid: int, *, dir_fd: int | None = ..., follow_symlinks: bool = ...
|
||||
) -> None: ... # Unix only
|
||||
|
||||
if sys.platform != "win32":
|
||||
@@ -614,36 +613,32 @@ def link(
|
||||
src: StrOrBytesPath,
|
||||
dst: StrOrBytesPath,
|
||||
*,
|
||||
src_dir_fd: Optional[int] = ...,
|
||||
dst_dir_fd: Optional[int] = ...,
|
||||
src_dir_fd: int | None = ...,
|
||||
dst_dir_fd: int | None = ...,
|
||||
follow_symlinks: bool = ...,
|
||||
) -> None: ...
|
||||
def lstat(path: StrOrBytesPath, *, dir_fd: Optional[int] = ...) -> stat_result: ...
|
||||
def mkdir(path: StrOrBytesPath, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
def lstat(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> stat_result: ...
|
||||
def mkdir(path: StrOrBytesPath, mode: int = ..., *, dir_fd: int | None = ...) -> None: ...
|
||||
|
||||
if sys.platform != "win32":
|
||||
def mkfifo(path: StrOrBytesPath, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ... # Unix only
|
||||
def mkfifo(path: StrOrBytesPath, mode: int = ..., *, dir_fd: int | None = ...) -> None: ... # Unix only
|
||||
|
||||
def makedirs(name: StrOrBytesPath, mode: int = ..., exist_ok: bool = ...) -> None: ...
|
||||
|
||||
if sys.platform != "win32":
|
||||
def mknod(path: StrOrBytesPath, mode: int = ..., device: int = ..., *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
def mknod(path: StrOrBytesPath, mode: int = ..., device: int = ..., *, dir_fd: int | None = ...) -> None: ...
|
||||
def major(__device: int) -> int: ...
|
||||
def minor(__device: int) -> int: ...
|
||||
def makedev(__major: int, __minor: int) -> int: ...
|
||||
def pathconf(path: _FdOrAnyPath, name: Union[str, int]) -> int: ... # Unix only
|
||||
def pathconf(path: _FdOrAnyPath, name: str | int) -> int: ... # Unix only
|
||||
|
||||
def readlink(path: Union[AnyStr, PathLike[AnyStr]], *, dir_fd: Optional[int] = ...) -> AnyStr: ...
|
||||
def remove(path: StrOrBytesPath, *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
def readlink(path: AnyStr | PathLike[AnyStr], *, dir_fd: int | None = ...) -> AnyStr: ...
|
||||
def remove(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> None: ...
|
||||
def removedirs(name: StrOrBytesPath) -> None: ...
|
||||
def rename(
|
||||
src: StrOrBytesPath, dst: StrOrBytesPath, *, src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...
|
||||
) -> None: ...
|
||||
def rename(src: StrOrBytesPath, dst: StrOrBytesPath, *, src_dir_fd: int | None = ..., dst_dir_fd: int | None = ...) -> None: ...
|
||||
def renames(old: StrOrBytesPath, new: StrOrBytesPath) -> None: ...
|
||||
def replace(
|
||||
src: StrOrBytesPath, dst: StrOrBytesPath, *, src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...
|
||||
) -> None: ...
|
||||
def rmdir(path: StrOrBytesPath, *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
def replace(src: StrOrBytesPath, dst: StrOrBytesPath, *, src_dir_fd: int | None = ..., dst_dir_fd: int | None = ...) -> None: ...
|
||||
def rmdir(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> None: ...
|
||||
|
||||
class _ScandirIterator(Iterator[DirEntry[AnyStr]], ContextManager[_ScandirIterator[AnyStr]]):
|
||||
def __next__(self) -> DirEntry[AnyStr]: ...
|
||||
@@ -655,15 +650,15 @@ if sys.version_info >= (3, 7):
|
||||
@overload
|
||||
def scandir(path: int) -> _ScandirIterator[str]: ...
|
||||
@overload
|
||||
def scandir(path: Union[AnyStr, PathLike[AnyStr]]) -> _ScandirIterator[AnyStr]: ...
|
||||
def scandir(path: AnyStr | PathLike[AnyStr]) -> _ScandirIterator[AnyStr]: ...
|
||||
|
||||
else:
|
||||
@overload
|
||||
def scandir(path: None = ...) -> _ScandirIterator[str]: ...
|
||||
@overload
|
||||
def scandir(path: Union[AnyStr, PathLike[AnyStr]]) -> _ScandirIterator[AnyStr]: ...
|
||||
def scandir(path: AnyStr | PathLike[AnyStr]) -> _ScandirIterator[AnyStr]: ...
|
||||
|
||||
def stat(path: _FdOrAnyPath, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> stat_result: ...
|
||||
def stat(path: _FdOrAnyPath, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> stat_result: ...
|
||||
|
||||
if sys.version_info < (3, 7):
|
||||
@overload
|
||||
@@ -674,28 +669,26 @@ if sys.version_info < (3, 7):
|
||||
if sys.platform != "win32":
|
||||
def statvfs(path: _FdOrAnyPath) -> statvfs_result: ... # Unix only
|
||||
|
||||
def symlink(
|
||||
src: StrOrBytesPath, dst: StrOrBytesPath, target_is_directory: bool = ..., *, dir_fd: Optional[int] = ...
|
||||
) -> None: ...
|
||||
def symlink(src: StrOrBytesPath, dst: StrOrBytesPath, target_is_directory: bool = ..., *, dir_fd: int | None = ...) -> None: ...
|
||||
|
||||
if sys.platform != "win32":
|
||||
def sync() -> None: ... # Unix only
|
||||
|
||||
def truncate(path: _FdOrAnyPath, length: int) -> None: ... # Unix only up to version 3.4
|
||||
def unlink(path: StrOrBytesPath, *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
def unlink(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> None: ...
|
||||
def utime(
|
||||
path: _FdOrAnyPath,
|
||||
times: Optional[Union[Tuple[int, int], Tuple[float, float]]] = ...,
|
||||
times: Tuple[int, int] | Tuple[float, float] | None = ...,
|
||||
*,
|
||||
ns: Tuple[int, int] = ...,
|
||||
dir_fd: Optional[int] = ...,
|
||||
dir_fd: int | None = ...,
|
||||
follow_symlinks: bool = ...,
|
||||
) -> None: ...
|
||||
|
||||
_OnError = Callable[[OSError], Any]
|
||||
|
||||
def walk(
|
||||
top: Union[AnyStr, PathLike[AnyStr]], topdown: bool = ..., onerror: Optional[_OnError] = ..., followlinks: bool = ...
|
||||
top: AnyStr | PathLike[AnyStr], topdown: bool = ..., onerror: _OnError | None = ..., followlinks: bool = ...
|
||||
) -> Iterator[Tuple[AnyStr, List[AnyStr], List[AnyStr]]]: ...
|
||||
|
||||
if sys.platform != "win32":
|
||||
@@ -704,32 +697,32 @@ if sys.platform != "win32":
|
||||
def fwalk(
|
||||
top: StrPath = ...,
|
||||
topdown: bool = ...,
|
||||
onerror: Optional[_OnError] = ...,
|
||||
onerror: _OnError | None = ...,
|
||||
*,
|
||||
follow_symlinks: bool = ...,
|
||||
dir_fd: Optional[int] = ...,
|
||||
dir_fd: int | None = ...,
|
||||
) -> Iterator[Tuple[str, List[str], List[str], int]]: ...
|
||||
@overload
|
||||
def fwalk(
|
||||
top: bytes,
|
||||
topdown: bool = ...,
|
||||
onerror: Optional[_OnError] = ...,
|
||||
onerror: _OnError | None = ...,
|
||||
*,
|
||||
follow_symlinks: bool = ...,
|
||||
dir_fd: Optional[int] = ...,
|
||||
dir_fd: int | None = ...,
|
||||
) -> Iterator[Tuple[bytes, List[bytes], List[bytes], int]]: ...
|
||||
else:
|
||||
def fwalk(
|
||||
top: StrPath = ...,
|
||||
topdown: bool = ...,
|
||||
onerror: Optional[_OnError] = ...,
|
||||
onerror: _OnError | None = ...,
|
||||
*,
|
||||
follow_symlinks: bool = ...,
|
||||
dir_fd: Optional[int] = ...,
|
||||
dir_fd: int | None = ...,
|
||||
) -> Iterator[Tuple[str, List[str], List[str], int]]: ...
|
||||
if sys.platform == "linux":
|
||||
def getxattr(path: _FdOrAnyPath, attribute: StrOrBytesPath, *, follow_symlinks: bool = ...) -> bytes: ...
|
||||
def listxattr(path: Optional[_FdOrAnyPath] = ..., *, follow_symlinks: bool = ...) -> List[str]: ...
|
||||
def listxattr(path: _FdOrAnyPath | None = ..., *, follow_symlinks: bool = ...) -> List[str]: ...
|
||||
def removexattr(path: _FdOrAnyPath, attribute: StrOrBytesPath, *, follow_symlinks: bool = ...) -> None: ...
|
||||
def setxattr(
|
||||
path: _FdOrAnyPath, attribute: StrOrBytesPath, value: bytes, flags: int = ..., *, follow_symlinks: bool = ...
|
||||
@@ -780,7 +773,7 @@ if sys.platform != "win32":
|
||||
|
||||
class _wrap_close(_TextIOWrapper):
|
||||
def __init__(self, stream: _TextIOWrapper, proc: Popen[str]) -> None: ...
|
||||
def close(self) -> Optional[int]: ... # type: ignore
|
||||
def close(self) -> int | None: ... # type: ignore
|
||||
|
||||
def popen(cmd: str, mode: str = ..., buffering: int = ...) -> _wrap_close: ...
|
||||
def spawnl(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: StrOrBytesPath) -> int: ...
|
||||
@@ -799,7 +792,7 @@ def times() -> times_result: ...
|
||||
def waitpid(__pid: int, __options: int) -> Tuple[int, int]: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
def startfile(path: StrOrBytesPath, operation: Optional[str] = ...) -> None: ...
|
||||
def startfile(path: StrOrBytesPath, operation: str | None = ...) -> None: ...
|
||||
|
||||
else:
|
||||
# Unix only
|
||||
@@ -838,13 +831,13 @@ if sys.platform != "win32":
|
||||
def sched_setaffinity(pid: int, mask: Iterable[int]) -> None: ... # some flavors of Unix
|
||||
def sched_getaffinity(pid: int) -> Set[int]: ... # some flavors of Unix
|
||||
|
||||
def cpu_count() -> Optional[int]: ...
|
||||
def cpu_count() -> int | None: ...
|
||||
|
||||
if sys.platform != "win32":
|
||||
# Unix only
|
||||
def confstr(__name: Union[str, int]) -> Optional[str]: ...
|
||||
def confstr(__name: str | int) -> str | None: ...
|
||||
def getloadavg() -> Tuple[float, float, float]: ...
|
||||
def sysconf(__name: Union[str, int]) -> int: ...
|
||||
def sysconf(__name: str | int) -> int: ...
|
||||
|
||||
if sys.platform == "linux":
|
||||
def getrandom(size: int, flags: int = ...) -> bytes: ...
|
||||
@@ -854,16 +847,16 @@ def urandom(__size: int) -> bytes: ...
|
||||
if sys.version_info >= (3, 7) and sys.platform != "win32":
|
||||
def register_at_fork(
|
||||
*,
|
||||
before: Optional[Callable[..., Any]] = ...,
|
||||
after_in_parent: Optional[Callable[..., Any]] = ...,
|
||||
after_in_child: Optional[Callable[..., Any]] = ...,
|
||||
before: Callable[..., Any] | None = ...,
|
||||
after_in_parent: Callable[..., Any] | None = ...,
|
||||
after_in_child: Callable[..., Any] | None = ...,
|
||||
) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
if sys.platform == "win32":
|
||||
class _AddedDllDirectory:
|
||||
path: Optional[str]
|
||||
def __init__(self, path: Optional[str], cookie: _T, remove_dll_directory: Callable[[_T], Any]) -> None: ...
|
||||
path: str | None
|
||||
def __init__(self, path: str | None, cookie: _T, remove_dll_directory: Callable[[_T], Any]) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *args: Any) -> None: ...
|
||||
|
||||
Reference in New Issue
Block a user