From 31f4b8cf80289fd876c6790033b10f9bce8b451e Mon Sep 17 00:00:00 2001 From: Abtin Date: Mon, 22 May 2023 16:44:00 +0200 Subject: [PATCH] add typing support to more aiofiles wrapped functions (#10175) add stubs for missing functions: - renames - unlink - link - listdir --- stubs/aiofiles/@tests/stubtest_allowlist.txt | 6 ++++ stubs/aiofiles/aiofiles/os.pyi | 36 +++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/stubs/aiofiles/@tests/stubtest_allowlist.txt b/stubs/aiofiles/@tests/stubtest_allowlist.txt index ae9f0d9a1..29651389f 100644 --- a/stubs/aiofiles/@tests/stubtest_allowlist.txt +++ b/stubs/aiofiles/@tests/stubtest_allowlist.txt @@ -58,13 +58,19 @@ aiofiles.threadpool.text.AsyncTextIndirectIOWrapper.writable # These functions get the wrong signature from functools.wraps() aiofiles.os.stat aiofiles.os.rename +aiofiles.os.renames aiofiles.os.replace aiofiles.os.remove +aiofiles.os.unlink aiofiles.os.mkdir aiofiles.os.makedirs +aiofiles.os.link +aiofiles.os.symlink +aiofiles.os.readlink aiofiles.os.rmdir aiofiles.os.removedirs aiofiles.os.scandir +aiofiles.os.listdir aiofiles.ospath.exists aiofiles.ospath.isfile aiofiles.ospath.isdir diff --git a/stubs/aiofiles/aiofiles/os.pyi b/stubs/aiofiles/aiofiles/os.pyi index ad15feec9..27a3c70a4 100644 --- a/stubs/aiofiles/aiofiles/os.pyi +++ b/stubs/aiofiles/aiofiles/os.pyi @@ -1,5 +1,5 @@ import sys -from _typeshed import FileDescriptorOrPath, GenericPath, ReadableBuffer, StrOrBytesPath +from _typeshed import BytesPath, FileDescriptorOrPath, GenericPath, ReadableBuffer, StrOrBytesPath, StrPath from asyncio.events import AbstractEventLoop from collections.abc import Sequence from os import _ScandirIterator, stat_result @@ -26,6 +26,9 @@ async def rename( loop: AbstractEventLoop | None = ..., executor: Any = ..., ) -> None: ... +async def renames( + old: StrOrBytesPath, new: StrOrBytesPath, loop: AbstractEventLoop | None = ..., executor: Any = ... +) -> None: ... async def replace( src: StrOrBytesPath, dst: StrOrBytesPath, @@ -38,12 +41,37 @@ async def replace( async def remove( path: StrOrBytesPath, *, dir_fd: int | None = None, loop: AbstractEventLoop | None = ..., executor: Any = ... ) -> None: ... +async def unlink( + path: StrOrBytesPath, *, dir_fd: int | None = ..., loop: AbstractEventLoop | None = ..., executor: Any = ... +) -> None: ... async def mkdir( path: StrOrBytesPath, mode: int = 511, *, dir_fd: int | None = None, loop: AbstractEventLoop | None = ..., executor: Any = ... ) -> None: ... async def makedirs( name: StrOrBytesPath, mode: int = 511, exist_ok: bool = False, *, loop: AbstractEventLoop | None = ..., executor: Any = ... ) -> None: ... +async def link( + src: StrOrBytesPath, + dst: StrOrBytesPath, + *, + src_dir_fd: int | None = ..., + dst_dir_fd: int | None = ..., + follow_symlinks: bool = ..., + loop: AbstractEventLoop | None = ..., + executor: Any = ..., +) -> None: ... +async def symlink( + src: StrOrBytesPath, + dst: StrOrBytesPath, + target_is_directory: bool = ..., + *, + dir_fd: int | None = ..., + loop: AbstractEventLoop | None = ..., + executor: Any = ..., +) -> None: ... +async def readlink( + path: AnyStr, *, dir_fd: int | None = ..., loop: AbstractEventLoop | None = ..., executor: Any = ... +) -> AnyStr: ... async def rmdir( path: StrOrBytesPath, *, dir_fd: int | None = None, loop: AbstractEventLoop | None = ..., executor: Any = ... ) -> None: ... @@ -56,6 +84,12 @@ async def scandir(path: int, *, loop: AbstractEventLoop | None = ..., executor: async def scandir( path: GenericPath[AnyStr], *, loop: AbstractEventLoop | None = ..., executor: Any = ... ) -> _ScandirIterator[AnyStr]: ... +@overload +async def listdir(path: StrPath | None, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> list[str]: ... +@overload +async def listdir(path: BytesPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> list[bytes]: ... +@overload +async def listdir(path: int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> list[str]: ... if sys.platform != "win32": @overload