From 5c667d28cac92e0f540ae08080f65da6cd8abc78 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 12 Nov 2022 18:27:12 -0500 Subject: [PATCH 1/3] Complete stubtest for `aiofiles` + fix on Windows --- stubs/aiofiles/@tests/stubtest_allowlist.txt | 6 +++--- stubs/aiofiles/@tests/stubtest_allowlist_darwin.txt | 2 ++ stubs/aiofiles/@tests/stubtest_allowlist_linux.txt | 2 ++ stubs/aiofiles/METADATA.toml | 5 +++++ stubs/aiofiles/aiofiles/os.pyi | 2 +- stubs/aiofiles/aiofiles/tempfile/temptypes.pyi | 7 +++++-- 6 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 stubs/aiofiles/@tests/stubtest_allowlist_darwin.txt create mode 100644 stubs/aiofiles/@tests/stubtest_allowlist_linux.txt diff --git a/stubs/aiofiles/@tests/stubtest_allowlist.txt b/stubs/aiofiles/@tests/stubtest_allowlist.txt index 9d7ef7baa49e..1cc191485acb 100644 --- a/stubs/aiofiles/@tests/stubtest_allowlist.txt +++ b/stubs/aiofiles/@tests/stubtest_allowlist.txt @@ -1,6 +1,3 @@ -# Some arguments only exist on FreeBSD and MacOS -aiofiles.os.sendfile - # These all delegate using *args,**kwargs, but stubs use signature of # method they are being delegated to. aiofiles.threadpool.binary.AsyncBufferedIOBase.close @@ -61,3 +58,6 @@ 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/@tests/stubtest_allowlist_darwin.txt b/stubs/aiofiles/@tests/stubtest_allowlist_darwin.txt new file mode 100644 index 000000000000..b0ea37bd4388 --- /dev/null +++ b/stubs/aiofiles/@tests/stubtest_allowlist_darwin.txt @@ -0,0 +1,2 @@ +# This function gets the wrong signature from functools.wraps() +aiofiles.os.sendfile diff --git a/stubs/aiofiles/@tests/stubtest_allowlist_linux.txt b/stubs/aiofiles/@tests/stubtest_allowlist_linux.txt new file mode 100644 index 000000000000..b0ea37bd4388 --- /dev/null +++ b/stubs/aiofiles/@tests/stubtest_allowlist_linux.txt @@ -0,0 +1,2 @@ +# This function gets the wrong signature from functools.wraps() +aiofiles.os.sendfile diff --git a/stubs/aiofiles/METADATA.toml b/stubs/aiofiles/METADATA.toml index 130d4fc2d894..359c45817b3c 100644 --- a/stubs/aiofiles/METADATA.toml +++ b/stubs/aiofiles/METADATA.toml @@ -1 +1,6 @@ version = "22.1.*" + +[tool.stubtest] +ignore_missing_stub = false +# linux and darwin are equivalent +platforms = ["linux", "win32"] diff --git a/stubs/aiofiles/aiofiles/os.pyi b/stubs/aiofiles/aiofiles/os.pyi index 98881cd1fc64..7433e8b9fda4 100644 --- a/stubs/aiofiles/aiofiles/os.pyi +++ b/stubs/aiofiles/aiofiles/os.pyi @@ -6,7 +6,7 @@ from os import stat_result from typing import Any, overload from typing_extensions import TypeAlias -from . import ospath +from aiofiles import ospath path = ospath diff --git a/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi b/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi index 61fdfb608504..6b66e27ece4d 100644 --- a/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi +++ b/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi @@ -5,8 +5,8 @@ from tempfile import TemporaryDirectory, _BytesMode from types import coroutine as coroutine from typing import TypeVar -from ..base import AsyncBase as AsyncBase -from ..threadpool.utils import ( +from aiofiles.base import AsyncBase as AsyncBase +from aiofiles.threadpool.utils import ( cond_delegate_to_executor as cond_delegate_to_executor, delegate_to_executor as delegate_to_executor, proxy_property_directly as proxy_property_directly, @@ -17,6 +17,7 @@ _T = TypeVar("_T") class AsyncSpooledTemporaryFile(AsyncBase[_T]): def fileno(self) -> Generator[Incomplete, Incomplete, Incomplete]: ... def rollover(self) -> Generator[Incomplete, Incomplete, Incomplete]: ... + async def close(self) -> None: ... async def flush(self) -> None: ... async def isatty(self) -> bool: ... # All must return `AnyStr`: @@ -37,6 +38,8 @@ class AsyncSpooledTemporaryFile(AsyncBase[_T]): def name(self) -> str: ... @property def newlines(self) -> str: ... + @property + def softspace(self) -> bool: ... # Both should work with `AnyStr`, like in `tempfile`: async def write(self, s: Incomplete) -> int: ... async def writelines(self, iterable: Iterable[Incomplete]) -> None: ... From 03dead67fb1c9392872fb8e2f65a30069d65892a Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 12 Nov 2022 21:12:23 -0500 Subject: [PATCH 2/3] Incomplete close parameters --- stubs/aiofiles/aiofiles/tempfile/temptypes.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi b/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi index 6b66e27ece4d..fc47fe7fb375 100644 --- a/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi +++ b/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi @@ -17,7 +17,7 @@ _T = TypeVar("_T") class AsyncSpooledTemporaryFile(AsyncBase[_T]): def fileno(self) -> Generator[Incomplete, Incomplete, Incomplete]: ... def rollover(self) -> Generator[Incomplete, Incomplete, Incomplete]: ... - async def close(self) -> None: ... + async def close(self, *args: Incomplete, **kwargs: Incomplete) -> None: ... async def flush(self) -> None: ... async def isatty(self) -> bool: ... # All must return `AnyStr`: From 3fb22833f4d4ce776f3af22f7c2d1c657d0be6bd Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 13 Nov 2022 03:08:11 -0500 Subject: [PATCH 3/3] Update AsyncSpooledTemporaryFile.close --- stubs/aiofiles/@tests/stubtest_allowlist.txt | 2 ++ stubs/aiofiles/aiofiles/tempfile/temptypes.pyi | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/stubs/aiofiles/@tests/stubtest_allowlist.txt b/stubs/aiofiles/@tests/stubtest_allowlist.txt index 1cc191485acb..a1858eca8fa9 100644 --- a/stubs/aiofiles/@tests/stubtest_allowlist.txt +++ b/stubs/aiofiles/@tests/stubtest_allowlist.txt @@ -48,6 +48,7 @@ aiofiles.ospath.samefile aiofiles.ospath.sameopenfile # Same issues as above +aiofiles.tempfile.temptypes.AsyncSpooledTemporaryFile.close aiofiles.tempfile.temptypes.AsyncSpooledTemporaryFile.fileno aiofiles.tempfile.temptypes.AsyncSpooledTemporaryFile.flush aiofiles.tempfile.temptypes.AsyncSpooledTemporaryFile.isatty @@ -61,3 +62,4 @@ aiofiles.tempfile.AiofilesContextManagerTempDir # Helper decorator, too complex to type aiofiles.os.wrap + diff --git a/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi b/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi index fc47fe7fb375..6b66e27ece4d 100644 --- a/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi +++ b/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi @@ -17,7 +17,7 @@ _T = TypeVar("_T") class AsyncSpooledTemporaryFile(AsyncBase[_T]): def fileno(self) -> Generator[Incomplete, Incomplete, Incomplete]: ... def rollover(self) -> Generator[Incomplete, Incomplete, Incomplete]: ... - async def close(self, *args: Incomplete, **kwargs: Incomplete) -> None: ... + async def close(self) -> None: ... async def flush(self) -> None: ... async def isatty(self) -> bool: ... # All must return `AnyStr`: