From 14b67a9b83020908279b78688678155744437577 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Tue, 15 Aug 2023 16:56:58 +0200 Subject: [PATCH 1/8] Bump aiofiles to 23.2.* --- stubs/aiofiles/@tests/stubtest_allowlist.txt | 3 -- stubs/aiofiles/METADATA.toml | 2 +- stubs/aiofiles/aiofiles/os.pyi | 30 +++++++++++++++++++ stubs/aiofiles/aiofiles/ospath.pyi | 6 +++- .../aiofiles/aiofiles/tempfile/temptypes.pyi | 1 - stubs/aiofiles/aiofiles/threadpool/utils.pyi | 1 - 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/stubs/aiofiles/@tests/stubtest_allowlist.txt b/stubs/aiofiles/@tests/stubtest_allowlist.txt index 29651389f688..3bf7029b44b7 100644 --- a/stubs/aiofiles/@tests/stubtest_allowlist.txt +++ b/stubs/aiofiles/@tests/stubtest_allowlist.txt @@ -93,6 +93,3 @@ aiofiles.tempfile.temptypes.AsyncTemporaryDirectory.cleanup # Metaclass differs: aiofiles.base.AiofilesContextManager aiofiles.tempfile.AiofilesContextManagerTempDir - -# Helper decorator, too complex to type -aiofiles.os.wrap diff --git a/stubs/aiofiles/METADATA.toml b/stubs/aiofiles/METADATA.toml index f9b51ecc6694..950f1bd80ddd 100644 --- a/stubs/aiofiles/METADATA.toml +++ b/stubs/aiofiles/METADATA.toml @@ -1,4 +1,4 @@ -version = "23.1.*" +version = "23.2.*" upstream_repository = "https://github.com/Tinche/aiofiles" [tool.stubtest] diff --git a/stubs/aiofiles/aiofiles/os.pyi b/stubs/aiofiles/aiofiles/os.pyi index 27a3c70a432d..11e194ce2836 100644 --- a/stubs/aiofiles/aiofiles/os.pyi +++ b/stubs/aiofiles/aiofiles/os.pyi @@ -6,6 +6,30 @@ from os import _ScandirIterator, stat_result from typing import Any, AnyStr, overload from aiofiles import ospath +from aiofiles.ospath import wrap as wrap + +__all__ = [ + "path", + "stat", + "statvfs", + "rename", + "renames", + "replace", + "remove", + "unlink", + "mkdir", + "makedirs", + "rmdir", + "removedirs", + "link", + "symlink", + "readlink", + "listdir", + "scandir", + "access", + "sendfile", + "wrap", +] path = ospath @@ -90,8 +114,13 @@ async def listdir(path: StrPath | None, *, loop: AbstractEventLoop | None = ..., 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]: ... +async def access( + path: FileDescriptorOrPath, mode: int, *, dir_fd: int | None = None, effective_ids: bool = False, follow_symlinks: bool = True +) -> bool: ... if sys.platform != "win32": + from os import statvfs_result + @overload async def sendfile( out_fd: int, in_fd: int, offset: int | None, count: int, *, loop: AbstractEventLoop | None = ..., executor: Any = ... @@ -109,3 +138,4 @@ if sys.platform != "win32": loop: AbstractEventLoop | None = ..., executor: Any = ..., ) -> int: ... # FreeBSD and Mac OS X only + async def statvfs(path: FileDescriptorOrPath) -> statvfs_result: ... # Unix only diff --git a/stubs/aiofiles/aiofiles/ospath.pyi b/stubs/aiofiles/aiofiles/ospath.pyi index e58e728984df..c7f3912e9da0 100644 --- a/stubs/aiofiles/aiofiles/ospath.pyi +++ b/stubs/aiofiles/aiofiles/ospath.pyi @@ -1,7 +1,11 @@ from _typeshed import FileDescriptorOrPath from asyncio.events import AbstractEventLoop -from typing import Any +from collections.abc import Awaitable, Callable +from typing import Any, TypeVar +_R = TypeVar("_R") + +def wrap(func: Callable[..., _R]) -> Callable[..., Awaitable[_R]]: ... async def exists(path: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ... async def isfile(path: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ... async def isdir(s: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ... diff --git a/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi b/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi index bb9fdcfca8c5..707d2ec66483 100644 --- a/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi +++ b/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi @@ -2,7 +2,6 @@ from _typeshed import Incomplete, OpenBinaryMode from asyncio import AbstractEventLoop from collections.abc import Generator, Iterable from tempfile import TemporaryDirectory -from types import coroutine as coroutine from typing import TypeVar from aiofiles.base import AsyncBase as AsyncBase diff --git a/stubs/aiofiles/aiofiles/threadpool/utils.pyi b/stubs/aiofiles/aiofiles/threadpool/utils.pyi index afff76d0d580..438a6851ef72 100644 --- a/stubs/aiofiles/aiofiles/threadpool/utils.pyi +++ b/stubs/aiofiles/aiofiles/threadpool/utils.pyi @@ -1,5 +1,4 @@ from collections.abc import Callable -from types import coroutine as coroutine from typing import TypeVar _T = TypeVar("_T", bound=type) From 136198964672c4db7faef756934aa7eb28f4fba3 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Tue, 15 Aug 2023 17:06:00 +0200 Subject: [PATCH 2/8] Update `__all__` for win32 --- stubs/aiofiles/aiofiles/os.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stubs/aiofiles/aiofiles/os.pyi b/stubs/aiofiles/aiofiles/os.pyi index 11e194ce2836..54e601040052 100644 --- a/stubs/aiofiles/aiofiles/os.pyi +++ b/stubs/aiofiles/aiofiles/os.pyi @@ -11,7 +11,6 @@ from aiofiles.ospath import wrap as wrap __all__ = [ "path", "stat", - "statvfs", "rename", "renames", "replace", @@ -27,10 +26,12 @@ __all__ = [ "listdir", "scandir", "access", - "sendfile", "wrap", ] +if sys.platform != "win32": + __all__ += ["statvfs", "sendfile"] + path = ospath async def stat( From 9a923a0af915cebccc867348dd486b5c9ab364da Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Tue, 15 Aug 2023 17:15:09 +0200 Subject: [PATCH 3/8] It seems sendfile() and statvfs() are available on Windows? --- stubs/aiofiles/aiofiles/os.pyi | 48 +++++++++++++++------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/stubs/aiofiles/aiofiles/os.pyi b/stubs/aiofiles/aiofiles/os.pyi index 54e601040052..cd08d6e09e0d 100644 --- a/stubs/aiofiles/aiofiles/os.pyi +++ b/stubs/aiofiles/aiofiles/os.pyi @@ -1,8 +1,7 @@ -import sys 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 +from os import _ScandirIterator, stat_result, statvfs_result from typing import Any, AnyStr, overload from aiofiles import ospath @@ -11,6 +10,7 @@ from aiofiles.ospath import wrap as wrap __all__ = [ "path", "stat", + "statvfs", "rename", "renames", "replace", @@ -26,12 +26,10 @@ __all__ = [ "listdir", "scandir", "access", + "sendfile", "wrap", ] -if sys.platform != "win32": - __all__ += ["statvfs", "sendfile"] - path = ospath async def stat( @@ -118,25 +116,21 @@ async def listdir(path: int, *, loop: AbstractEventLoop | None = ..., executor: async def access( path: FileDescriptorOrPath, mode: int, *, dir_fd: int | None = None, effective_ids: bool = False, follow_symlinks: bool = True ) -> bool: ... - -if sys.platform != "win32": - from os import statvfs_result - - @overload - async def sendfile( - out_fd: int, in_fd: int, offset: int | None, count: int, *, loop: AbstractEventLoop | None = ..., executor: Any = ... - ) -> int: ... - @overload - async def sendfile( - out_fd: int, - in_fd: int, - offset: int, - count: int, - headers: Sequence[ReadableBuffer] = ..., - trailers: Sequence[ReadableBuffer] = ..., - flags: int = ..., - *, - loop: AbstractEventLoop | None = ..., - executor: Any = ..., - ) -> int: ... # FreeBSD and Mac OS X only - async def statvfs(path: FileDescriptorOrPath) -> statvfs_result: ... # Unix only +@overload +async def sendfile( + out_fd: int, in_fd: int, offset: int | None, count: int, *, loop: AbstractEventLoop | None = ..., executor: Any = ... +) -> int: ... +@overload +async def sendfile( + out_fd: int, + in_fd: int, + offset: int, + count: int, + headers: Sequence[ReadableBuffer] = ..., + trailers: Sequence[ReadableBuffer] = ..., + flags: int = ..., + *, + loop: AbstractEventLoop | None = ..., + executor: Any = ..., +) -> int: ... # FreeBSD and Mac OS X only +async def statvfs(path: FileDescriptorOrPath) -> statvfs_result: ... # Unix only From 9bb8cef1711b5a6282a8b4ae360ead3d0e7be41e Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Tue, 15 Aug 2023 18:06:57 +0200 Subject: [PATCH 4/8] Revert "It seems sendfile() and statvfs() are available on Windows?" This reverts commit 9a923a0af915cebccc867348dd486b5c9ab364da. --- stubs/aiofiles/aiofiles/os.pyi | 48 +++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/stubs/aiofiles/aiofiles/os.pyi b/stubs/aiofiles/aiofiles/os.pyi index cd08d6e09e0d..54e601040052 100644 --- a/stubs/aiofiles/aiofiles/os.pyi +++ b/stubs/aiofiles/aiofiles/os.pyi @@ -1,7 +1,8 @@ +import sys 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, statvfs_result +from os import _ScandirIterator, stat_result from typing import Any, AnyStr, overload from aiofiles import ospath @@ -10,7 +11,6 @@ from aiofiles.ospath import wrap as wrap __all__ = [ "path", "stat", - "statvfs", "rename", "renames", "replace", @@ -26,10 +26,12 @@ __all__ = [ "listdir", "scandir", "access", - "sendfile", "wrap", ] +if sys.platform != "win32": + __all__ += ["statvfs", "sendfile"] + path = ospath async def stat( @@ -116,21 +118,25 @@ async def listdir(path: int, *, loop: AbstractEventLoop | None = ..., executor: async def access( path: FileDescriptorOrPath, mode: int, *, dir_fd: int | None = None, effective_ids: bool = False, follow_symlinks: bool = True ) -> bool: ... -@overload -async def sendfile( - out_fd: int, in_fd: int, offset: int | None, count: int, *, loop: AbstractEventLoop | None = ..., executor: Any = ... -) -> int: ... -@overload -async def sendfile( - out_fd: int, - in_fd: int, - offset: int, - count: int, - headers: Sequence[ReadableBuffer] = ..., - trailers: Sequence[ReadableBuffer] = ..., - flags: int = ..., - *, - loop: AbstractEventLoop | None = ..., - executor: Any = ..., -) -> int: ... # FreeBSD and Mac OS X only -async def statvfs(path: FileDescriptorOrPath) -> statvfs_result: ... # Unix only + +if sys.platform != "win32": + from os import statvfs_result + + @overload + async def sendfile( + out_fd: int, in_fd: int, offset: int | None, count: int, *, loop: AbstractEventLoop | None = ..., executor: Any = ... + ) -> int: ... + @overload + async def sendfile( + out_fd: int, + in_fd: int, + offset: int, + count: int, + headers: Sequence[ReadableBuffer] = ..., + trailers: Sequence[ReadableBuffer] = ..., + flags: int = ..., + *, + loop: AbstractEventLoop | None = ..., + executor: Any = ..., + ) -> int: ... # FreeBSD and Mac OS X only + async def statvfs(path: FileDescriptorOrPath) -> statvfs_result: ... # Unix only From b894a109fd68030ba77e83f374b46727fc4c24c3 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Tue, 15 Aug 2023 18:20:39 +0200 Subject: [PATCH 5/8] Disable stubtest for now --- stubs/aiofiles/METADATA.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stubs/aiofiles/METADATA.toml b/stubs/aiofiles/METADATA.toml index 950f1bd80ddd..e8888f23e353 100644 --- a/stubs/aiofiles/METADATA.toml +++ b/stubs/aiofiles/METADATA.toml @@ -4,3 +4,7 @@ upstream_repository = "https://github.com/Tinche/aiofiles" [tool.stubtest] # linux and darwin are equivalent platforms = ["linux", "win32"] +# Currently we are in a pickle, because aiofiles.os.__all__ is incorrect at +# runtime when running on win32. (https://github.com/Tinche/aiofiles/pull/174) +# This means that stubtest is either correct on Windows or all other platforms. +skip = true From 4aa9a047c7bff2f1504547f35a196a76a527f23d Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 16 Aug 2023 12:46:21 +0200 Subject: [PATCH 6/8] Revert "Disable stubtest for now" This reverts commit b894a109fd68030ba77e83f374b46727fc4c24c3. --- stubs/aiofiles/METADATA.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stubs/aiofiles/METADATA.toml b/stubs/aiofiles/METADATA.toml index e8888f23e353..950f1bd80ddd 100644 --- a/stubs/aiofiles/METADATA.toml +++ b/stubs/aiofiles/METADATA.toml @@ -4,7 +4,3 @@ upstream_repository = "https://github.com/Tinche/aiofiles" [tool.stubtest] # linux and darwin are equivalent platforms = ["linux", "win32"] -# Currently we are in a pickle, because aiofiles.os.__all__ is incorrect at -# runtime when running on win32. (https://github.com/Tinche/aiofiles/pull/174) -# This means that stubtest is either correct on Windows or all other platforms. -skip = true From f13fd7f015624d5df0e52e8751f8e759e0f7cb4d Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 16 Aug 2023 12:49:25 +0200 Subject: [PATCH 7/8] Add __all__ to allowlist on win32 --- stubs/aiofiles/@tests/stubtest_allowlist_win32.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 stubs/aiofiles/@tests/stubtest_allowlist_win32.txt diff --git a/stubs/aiofiles/@tests/stubtest_allowlist_win32.txt b/stubs/aiofiles/@tests/stubtest_allowlist_win32.txt new file mode 100644 index 000000000000..ad4bd81a4547 --- /dev/null +++ b/stubs/aiofiles/@tests/stubtest_allowlist_win32.txt @@ -0,0 +1,3 @@ +# At runtime, __all__ includes some items that are not available on Windows. +# https://github.com/Tinche/aiofiles/pull/174 +aiofiles.os.__all__ From 227917d5aa2bf682d01d06a66e5a1ecea539620a Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 16 Aug 2023 12:54:10 +0200 Subject: [PATCH 8/8] Update stubs/aiofiles/@tests/stubtest_allowlist_win32.txt Co-authored-by: Alex Waygood --- stubs/aiofiles/@tests/stubtest_allowlist_win32.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stubs/aiofiles/@tests/stubtest_allowlist_win32.txt b/stubs/aiofiles/@tests/stubtest_allowlist_win32.txt index ad4bd81a4547..7bd650ce17a5 100644 --- a/stubs/aiofiles/@tests/stubtest_allowlist_win32.txt +++ b/stubs/aiofiles/@tests/stubtest_allowlist_win32.txt @@ -1,3 +1,5 @@ # At runtime, __all__ includes some items that are not available on Windows. # https://github.com/Tinche/aiofiles/pull/174 aiofiles.os.__all__ +aiofiles.os.sendfile +aiofiles.os.statvfs