mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 05:24:52 +08:00
AnyStr cleanup (#5487)
* Replace all uses of StrPath, BytesPath, and AnyPath in Python 2 stubs. * Add StrOrBytesPath as preferred alias for AnyPath. * Replace all remaining AnyPath instances with StrOrBytesPath. * Mark AnyPath as obsolete. Part of #5470
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import sys
|
||||
from _typeshed import (
|
||||
AnyPath,
|
||||
FileDescriptorLike,
|
||||
OpenBinaryMode,
|
||||
OpenBinaryModeReading,
|
||||
OpenBinaryModeUpdating,
|
||||
OpenBinaryModeWriting,
|
||||
OpenTextMode,
|
||||
StrOrBytesPath,
|
||||
StrPath,
|
||||
)
|
||||
from builtins import OSError
|
||||
@@ -311,7 +311,7 @@ class stat_result:
|
||||
class PathLike(Protocol[_AnyStr_co]):
|
||||
def __fspath__(self) -> _AnyStr_co: ...
|
||||
|
||||
_FdOrAnyPath = Union[int, AnyPath]
|
||||
_FdOrAnyPath = Union[int, StrOrBytesPath]
|
||||
|
||||
class DirEntry(Generic[AnyStr]):
|
||||
# This is what the scandir interator yields
|
||||
@@ -368,8 +368,8 @@ if sys.platform != "win32":
|
||||
f_namemax: int
|
||||
|
||||
# ----- os function stubs -----
|
||||
def fsencode(filename: AnyPath) -> bytes: ...
|
||||
def fsdecode(filename: AnyPath) -> str: ...
|
||||
def fsencode(filename: StrOrBytesPath) -> bytes: ...
|
||||
def fsdecode(filename: StrOrBytesPath) -> str: ...
|
||||
@overload
|
||||
def fspath(path: str) -> str: ...
|
||||
@overload
|
||||
@@ -528,7 +528,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: AnyPath, flags: int, mode: int = ..., *, dir_fd: Optional[int] = ...) -> int: ...
|
||||
def open(path: StrOrBytesPath, flags: int, mode: int = ..., *, dir_fd: Optional[int] = ...) -> int: ...
|
||||
def pipe() -> Tuple[int, int]: ...
|
||||
def read(__fd: int, __length: int) -> bytes: ...
|
||||
|
||||
@@ -595,43 +595,52 @@ def getcwdb() -> bytes: ...
|
||||
def chmod(path: _FdOrAnyPath, mode: int, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> None: ...
|
||||
|
||||
if sys.platform != "win32":
|
||||
def chflags(path: AnyPath, flags: int, follow_symlinks: bool = ...) -> None: ... # some flavors of Unix
|
||||
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 = ...
|
||||
) -> None: ... # Unix only
|
||||
|
||||
if sys.platform != "win32":
|
||||
# Unix only
|
||||
def chroot(path: AnyPath) -> None: ...
|
||||
def lchflags(path: AnyPath, flags: int) -> None: ...
|
||||
def lchmod(path: AnyPath, mode: int) -> None: ...
|
||||
def lchown(path: AnyPath, uid: int, gid: int) -> None: ...
|
||||
def chroot(path: StrOrBytesPath) -> None: ...
|
||||
def lchflags(path: StrOrBytesPath, flags: int) -> None: ...
|
||||
def lchmod(path: StrOrBytesPath, mode: int) -> None: ...
|
||||
def lchown(path: StrOrBytesPath, uid: int, gid: int) -> None: ...
|
||||
|
||||
def link(
|
||||
src: AnyPath, dst: AnyPath, *, src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ..., follow_symlinks: bool = ...
|
||||
src: StrOrBytesPath,
|
||||
dst: StrOrBytesPath,
|
||||
*,
|
||||
src_dir_fd: Optional[int] = ...,
|
||||
dst_dir_fd: Optional[int] = ...,
|
||||
follow_symlinks: bool = ...,
|
||||
) -> None: ...
|
||||
def lstat(path: AnyPath, *, dir_fd: Optional[int] = ...) -> stat_result: ...
|
||||
def mkdir(path: AnyPath, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
def lstat(path: StrOrBytesPath, *, dir_fd: Optional[int] = ...) -> stat_result: ...
|
||||
def mkdir(path: StrOrBytesPath, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
|
||||
if sys.platform != "win32":
|
||||
def mkfifo(path: AnyPath, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ... # Unix only
|
||||
def mkfifo(path: StrOrBytesPath, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ... # Unix only
|
||||
|
||||
def makedirs(name: AnyPath, mode: int = ..., exist_ok: bool = ...) -> None: ...
|
||||
def makedirs(name: StrOrBytesPath, mode: int = ..., exist_ok: bool = ...) -> None: ...
|
||||
|
||||
if sys.platform != "win32":
|
||||
def mknod(path: AnyPath, mode: int = ..., device: int = ..., *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
def mknod(path: StrOrBytesPath, mode: int = ..., device: int = ..., *, dir_fd: Optional[int] = ...) -> 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 readlink(path: Union[AnyStr, PathLike[AnyStr]], *, dir_fd: Optional[int] = ...) -> AnyStr: ...
|
||||
def remove(path: AnyPath, *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
def removedirs(name: AnyPath) -> None: ...
|
||||
def rename(src: AnyPath, dst: AnyPath, *, src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...) -> None: ...
|
||||
def renames(old: AnyPath, new: AnyPath) -> None: ...
|
||||
def replace(src: AnyPath, dst: AnyPath, *, src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...) -> None: ...
|
||||
def rmdir(path: AnyPath, *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
def remove(path: StrOrBytesPath, *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
def removedirs(name: StrOrBytesPath) -> None: ...
|
||||
def rename(
|
||||
src: StrOrBytesPath, dst: StrOrBytesPath, *, src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...
|
||||
) -> 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: ...
|
||||
|
||||
class _ScandirIterator(Iterator[DirEntry[AnyStr]], ContextManager[_ScandirIterator[AnyStr]]):
|
||||
def __next__(self) -> DirEntry[AnyStr]: ...
|
||||
@@ -662,13 +671,15 @@ if sys.version_info < (3, 7):
|
||||
if sys.platform != "win32":
|
||||
def statvfs(path: _FdOrAnyPath) -> statvfs_result: ... # Unix only
|
||||
|
||||
def symlink(src: AnyPath, dst: AnyPath, target_is_directory: bool = ..., *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
def symlink(
|
||||
src: StrOrBytesPath, dst: StrOrBytesPath, target_is_directory: bool = ..., *, dir_fd: Optional[int] = ...
|
||||
) -> 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: AnyPath, *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
def unlink(path: StrOrBytesPath, *, dir_fd: Optional[int] = ...) -> None: ...
|
||||
def utime(
|
||||
path: _FdOrAnyPath,
|
||||
times: Optional[Union[Tuple[int, int], Tuple[float, float]]] = ...,
|
||||
@@ -714,22 +725,22 @@ if sys.platform != "win32":
|
||||
dir_fd: Optional[int] = ...,
|
||||
) -> Iterator[Tuple[str, List[str], List[str], int]]: ...
|
||||
if sys.platform == "linux":
|
||||
def getxattr(path: _FdOrAnyPath, attribute: AnyPath, *, follow_symlinks: bool = ...) -> bytes: ...
|
||||
def getxattr(path: _FdOrAnyPath, attribute: StrOrBytesPath, *, follow_symlinks: bool = ...) -> bytes: ...
|
||||
def listxattr(path: Optional[_FdOrAnyPath] = ..., *, follow_symlinks: bool = ...) -> List[str]: ...
|
||||
def removexattr(path: _FdOrAnyPath, attribute: AnyPath, *, follow_symlinks: bool = ...) -> None: ...
|
||||
def removexattr(path: _FdOrAnyPath, attribute: StrOrBytesPath, *, follow_symlinks: bool = ...) -> None: ...
|
||||
def setxattr(
|
||||
path: _FdOrAnyPath, attribute: AnyPath, value: bytes, flags: int = ..., *, follow_symlinks: bool = ...
|
||||
path: _FdOrAnyPath, attribute: StrOrBytesPath, value: bytes, flags: int = ..., *, follow_symlinks: bool = ...
|
||||
) -> None: ...
|
||||
|
||||
def abort() -> NoReturn: ...
|
||||
|
||||
# These are defined as execl(file, *args) but the first *arg is mandatory.
|
||||
def execl(file: AnyPath, __arg0: AnyPath, *args: AnyPath) -> NoReturn: ...
|
||||
def execlp(file: AnyPath, __arg0: AnyPath, *args: AnyPath) -> NoReturn: ...
|
||||
def execl(file: StrOrBytesPath, __arg0: StrOrBytesPath, *args: StrOrBytesPath) -> NoReturn: ...
|
||||
def execlp(file: StrOrBytesPath, __arg0: StrOrBytesPath, *args: StrOrBytesPath) -> NoReturn: ...
|
||||
|
||||
# These are: execle(file, *args, env) but env is pulled from the last element of the args.
|
||||
def execle(file: AnyPath, __arg0: AnyPath, *args: Any) -> NoReturn: ...
|
||||
def execlpe(file: AnyPath, __arg0: AnyPath, *args: Any) -> NoReturn: ...
|
||||
def execle(file: StrOrBytesPath, __arg0: StrOrBytesPath, *args: Any) -> NoReturn: ...
|
||||
def execlpe(file: StrOrBytesPath, __arg0: StrOrBytesPath, *args: Any) -> NoReturn: ...
|
||||
|
||||
# The docs say `args: tuple or list of strings`
|
||||
# The implementation enforces tuple or list so we can't use Sequence.
|
||||
@@ -737,7 +748,7 @@ def execlpe(file: AnyPath, __arg0: AnyPath, *args: Any) -> NoReturn: ...
|
||||
# in practice, and doing so would explode the number of combinations in this already long union.
|
||||
# All these combinations are necessary due to List being invariant.
|
||||
_ExecVArgs = Union[
|
||||
Tuple[AnyPath, ...],
|
||||
Tuple[StrOrBytesPath, ...],
|
||||
List[bytes],
|
||||
List[str],
|
||||
List[PathLike[Any]],
|
||||
@@ -748,10 +759,10 @@ _ExecVArgs = Union[
|
||||
]
|
||||
_ExecEnv = Union[Mapping[bytes, Union[bytes, str]], Mapping[str, Union[bytes, str]]]
|
||||
|
||||
def execv(__path: AnyPath, __argv: _ExecVArgs) -> NoReturn: ...
|
||||
def execv(__path: StrOrBytesPath, __argv: _ExecVArgs) -> NoReturn: ...
|
||||
def execve(path: _FdOrAnyPath, argv: _ExecVArgs, env: _ExecEnv) -> NoReturn: ...
|
||||
def execvp(file: AnyPath, args: _ExecVArgs) -> NoReturn: ...
|
||||
def execvpe(file: AnyPath, args: _ExecVArgs, env: _ExecEnv) -> NoReturn: ...
|
||||
def execvp(file: StrOrBytesPath, args: _ExecVArgs) -> NoReturn: ...
|
||||
def execvpe(file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> NoReturn: ...
|
||||
def _exit(status: int) -> NoReturn: ...
|
||||
def kill(__pid: int, __signal: int) -> None: ...
|
||||
|
||||
@@ -769,30 +780,30 @@ class _wrap_close(_TextIOWrapper):
|
||||
def close(self) -> Optional[int]: ... # type: ignore
|
||||
|
||||
def popen(cmd: str, mode: str = ..., buffering: int = ...) -> _wrap_close: ...
|
||||
def spawnl(mode: int, file: AnyPath, arg0: AnyPath, *args: AnyPath) -> int: ...
|
||||
def spawnle(mode: int, file: AnyPath, arg0: AnyPath, *args: Any) -> int: ... # Imprecise sig
|
||||
def spawnl(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: StrOrBytesPath) -> int: ...
|
||||
def spawnle(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: Any) -> int: ... # Imprecise sig
|
||||
|
||||
if sys.platform != "win32":
|
||||
def spawnv(mode: int, file: AnyPath, args: _ExecVArgs) -> int: ...
|
||||
def spawnve(mode: int, file: AnyPath, args: _ExecVArgs, env: _ExecEnv) -> int: ...
|
||||
def spawnv(mode: int, file: StrOrBytesPath, args: _ExecVArgs) -> int: ...
|
||||
def spawnve(mode: int, file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> int: ...
|
||||
|
||||
else:
|
||||
def spawnv(__mode: int, __path: AnyPath, __argv: _ExecVArgs) -> int: ...
|
||||
def spawnve(__mode: int, __path: AnyPath, __argv: _ExecVArgs, __env: _ExecEnv) -> int: ...
|
||||
def spawnv(__mode: int, __path: StrOrBytesPath, __argv: _ExecVArgs) -> int: ...
|
||||
def spawnve(__mode: int, __path: StrOrBytesPath, __argv: _ExecVArgs, __env: _ExecEnv) -> int: ...
|
||||
|
||||
def system(command: AnyPath) -> int: ...
|
||||
def system(command: StrOrBytesPath) -> int: ...
|
||||
def times() -> times_result: ...
|
||||
def waitpid(__pid: int, __options: int) -> Tuple[int, int]: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
def startfile(path: AnyPath, operation: Optional[str] = ...) -> None: ...
|
||||
def startfile(path: StrOrBytesPath, operation: Optional[str] = ...) -> None: ...
|
||||
|
||||
else:
|
||||
# Unix only
|
||||
def spawnlp(mode: int, file: AnyPath, arg0: AnyPath, *args: AnyPath) -> int: ...
|
||||
def spawnlpe(mode: int, file: AnyPath, arg0: AnyPath, *args: Any) -> int: ... # Imprecise signature
|
||||
def spawnvp(mode: int, file: AnyPath, args: _ExecVArgs) -> int: ...
|
||||
def spawnvpe(mode: int, file: AnyPath, args: _ExecVArgs, env: _ExecEnv) -> int: ...
|
||||
def spawnlp(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: StrOrBytesPath) -> int: ...
|
||||
def spawnlpe(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: Any) -> int: ... # Imprecise signature
|
||||
def spawnvp(mode: int, file: StrOrBytesPath, args: _ExecVArgs) -> int: ...
|
||||
def spawnvpe(mode: int, file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> int: ...
|
||||
def wait() -> Tuple[int, int]: ... # Unix only
|
||||
if sys.platform != "darwin":
|
||||
from posix import waitid_result
|
||||
|
||||
Reference in New Issue
Block a user