Use the FileDescriptorOrPath alias consistently in the stdlib (#9513)

This commit is contained in:
Avasam
2023-01-12 13:14:48 -05:00
committed by GitHub
parent f64807a468
commit aad1a14890
12 changed files with 61 additions and 57 deletions

View File

@@ -3,6 +3,7 @@ from _typeshed import (
AnyStr_co,
BytesPath,
FileDescriptorLike,
FileDescriptorOrPath,
GenericPath,
OpenBinaryMode,
OpenBinaryModeReading,
@@ -370,9 +371,6 @@ def listdir(path: StrPath | None = ...) -> list[str]: ...
def listdir(path: BytesPath) -> list[bytes]: ...
@overload
def listdir(path: int) -> list[str]: ...
_FdOrAnyPath: TypeAlias = int | StrOrBytesPath
@final
class DirEntry(Generic[AnyStr]):
# This is what the scandir iterator yields
@@ -676,16 +674,16 @@ if sys.platform != "win32":
def write(__fd: int, __data: ReadableBuffer) -> int: ...
def access(
path: _FdOrAnyPath, mode: int, *, dir_fd: int | None = ..., effective_ids: bool = ..., follow_symlinks: bool = ...
path: FileDescriptorOrPath, mode: int, *, dir_fd: int | None = ..., effective_ids: bool = ..., follow_symlinks: bool = ...
) -> bool: ...
def chdir(path: _FdOrAnyPath) -> None: ...
def chdir(path: FileDescriptorOrPath) -> None: ...
if sys.platform != "win32":
def fchdir(fd: FileDescriptorLike) -> None: ...
def getcwd() -> str: ...
def getcwdb() -> bytes: ...
def chmod(path: _FdOrAnyPath, mode: int, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> None: ...
def chmod(path: FileDescriptorOrPath, mode: int, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> None: ...
if sys.platform != "win32" and sys.platform != "linux":
def chflags(path: StrOrBytesPath, flags: int, follow_symlinks: bool = ...) -> None: ... # some flavors of Unix
@@ -694,7 +692,9 @@ if sys.platform != "win32" and sys.platform != "linux":
if sys.platform != "win32":
def chroot(path: StrOrBytesPath) -> None: ...
def chown(path: _FdOrAnyPath, uid: int, gid: int, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> None: ...
def chown(
path: FileDescriptorOrPath, uid: int, gid: int, *, dir_fd: int | None = ..., follow_symlinks: bool = ...
) -> None: ...
def lchown(path: StrOrBytesPath, uid: int, gid: int) -> None: ...
def link(
@@ -718,7 +718,7 @@ if sys.platform != "win32":
def major(__device: int) -> int: ...
def minor(__device: int) -> int: ...
def makedev(__major: int, __minor: int) -> int: ...
def pathconf(path: _FdOrAnyPath, name: str | int) -> int: ... # Unix only
def pathconf(path: FileDescriptorOrPath, name: str | int) -> int: ... # Unix only
def readlink(path: GenericPath[AnyStr], *, dir_fd: int | None = ...) -> AnyStr: ...
def remove(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> None: ...
@@ -739,20 +739,20 @@ def scandir(path: None = ...) -> _ScandirIterator[str]: ...
def scandir(path: int) -> _ScandirIterator[str]: ...
@overload
def scandir(path: GenericPath[AnyStr]) -> _ScandirIterator[AnyStr]: ...
def stat(path: _FdOrAnyPath, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> stat_result: ...
def stat(path: FileDescriptorOrPath, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> stat_result: ...
if sys.platform != "win32":
def statvfs(path: _FdOrAnyPath) -> statvfs_result: ... # Unix only
def statvfs(path: FileDescriptorOrPath) -> statvfs_result: ... # Unix only
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 truncate(path: FileDescriptorOrPath, length: int) -> None: ... # Unix only up to version 3.4
def unlink(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> None: ...
def utime(
path: _FdOrAnyPath,
path: FileDescriptorOrPath,
times: tuple[int, int] | tuple[float, float] | None = ...,
*,
ns: tuple[int, int] = ...,
@@ -786,11 +786,16 @@ if sys.platform != "win32":
dir_fd: int | None = ...,
) -> Iterator[tuple[bytes, list[bytes], list[bytes], int]]: ...
if sys.platform == "linux":
def getxattr(path: _FdOrAnyPath, attribute: StrOrBytesPath, *, follow_symlinks: bool = ...) -> bytes: ...
def listxattr(path: _FdOrAnyPath | None = ..., *, follow_symlinks: bool = ...) -> list[str]: ...
def removexattr(path: _FdOrAnyPath, attribute: StrOrBytesPath, *, follow_symlinks: bool = ...) -> None: ...
def getxattr(path: FileDescriptorOrPath, attribute: StrOrBytesPath, *, follow_symlinks: bool = ...) -> bytes: ...
def listxattr(path: FileDescriptorOrPath | None = ..., *, follow_symlinks: bool = ...) -> list[str]: ...
def removexattr(path: FileDescriptorOrPath, attribute: StrOrBytesPath, *, follow_symlinks: bool = ...) -> None: ...
def setxattr(
path: _FdOrAnyPath, attribute: StrOrBytesPath, value: ReadableBuffer, flags: int = ..., *, follow_symlinks: bool = ...
path: FileDescriptorOrPath,
attribute: StrOrBytesPath,
value: ReadableBuffer,
flags: int = ...,
*,
follow_symlinks: bool = ...,
) -> None: ...
def abort() -> NoReturn: ...
@@ -825,7 +830,7 @@ _ExecVArgs: TypeAlias = (
_ExecEnv: TypeAlias = Mapping[bytes, bytes | str] | Mapping[str, bytes | str]
def execv(__path: StrOrBytesPath, __argv: _ExecVArgs) -> NoReturn: ...
def execve(path: _FdOrAnyPath, argv: _ExecVArgs, env: _ExecEnv) -> NoReturn: ...
def execve(path: FileDescriptorOrPath, argv: _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: ...