diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 0ca5a6161..ac04bab04 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -21,7 +21,6 @@ "stdlib/xml/dom/minidom.pyi", "stdlib/xml/dom/pulldom.pyi", "stdlib/xml/sax", - "stubs/aiofiles/aiofiles/tempfile/temptypes.pyi", "stubs/aiofiles/aiofiles/threadpool/utils.pyi", "stubs/annoy/annoy/annoylib.pyi", "stubs/aws-xray-sdk", diff --git a/stubs/aiofiles/@tests/stubtest_allowlist.txt b/stubs/aiofiles/@tests/stubtest_allowlist.txt index a79814533..d715b3f88 100644 --- a/stubs/aiofiles/@tests/stubtest_allowlist.txt +++ b/stubs/aiofiles/@tests/stubtest_allowlist.txt @@ -54,7 +54,6 @@ aiofiles.ospath.sameopenfile aiofiles.tempfile.temptypes.AsyncSpooledTemporaryFile.fileno aiofiles.tempfile.temptypes.AsyncSpooledTemporaryFile.flush aiofiles.tempfile.temptypes.AsyncSpooledTemporaryFile.isatty -aiofiles.tempfile.temptypes.AsyncSpooledTemporaryFile.newlines aiofiles.tempfile.temptypes.AsyncSpooledTemporaryFile.rollover aiofiles.tempfile.temptypes.AsyncSpooledTemporaryFile.tell aiofiles.tempfile.temptypes.AsyncTemporaryDirectory.cleanup diff --git a/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi b/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi index db6f26b55..61fdfb608 100644 --- a/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi +++ b/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi @@ -1,6 +1,7 @@ from _typeshed import Incomplete from asyncio import AbstractEventLoop -from collections.abc import Generator +from collections.abc import Generator, Iterable +from tempfile import TemporaryDirectory, _BytesMode from types import coroutine as coroutine from typing import TypeVar @@ -18,29 +19,33 @@ class AsyncSpooledTemporaryFile(AsyncBase[_T]): def rollover(self) -> Generator[Incomplete, Incomplete, Incomplete]: ... async def flush(self) -> None: ... async def isatty(self) -> bool: ... - async def read(self, __n: int = ...): ... - async def readline(self, __limit: int | None = ...): ... - async def readlines(self, __hint: int = ...): ... + # All must return `AnyStr`: + async def read(self, __n: int = ...) -> Incomplete: ... + async def readline(self, __limit: int | None = ...) -> Incomplete: ... + async def readlines(self, __hint: int = ...) -> list[Incomplete]: ... + # --- async def seek(self, offset: int, whence: int = ...) -> int: ... async def tell(self) -> int: ... async def truncate(self, size: int | None = ...) -> None: ... @property - def closed(self): ... + def closed(self) -> bool: ... @property - def encoding(self): ... + def encoding(self) -> str: ... @property - def mode(self): ... + def mode(self) -> _BytesMode: ... @property - def name(self): ... - async def newlines(self): ... + def name(self) -> str: ... @property - def softspace(self): ... - async def write(self, s): ... - async def writelines(self, iterable): ... + def newlines(self) -> str: ... + # Both should work with `AnyStr`, like in `tempfile`: + async def write(self, s: Incomplete) -> int: ... + async def writelines(self, iterable: Iterable[Incomplete]) -> None: ... class AsyncTemporaryDirectory: async def cleanup(self) -> None: ... @property - def name(self): ... - def __init__(self, file, loop: AbstractEventLoop | None, executor: Incomplete | None) -> None: ... + def name(self) -> Incomplete: ... # should be `AnyStr` + def __init__( + self, file: TemporaryDirectory[Incomplete], loop: AbstractEventLoop | None, executor: Incomplete | None + ) -> None: ... async def close(self) -> None: ... diff --git a/stubs/aiofiles/aiofiles/threadpool/utils.pyi b/stubs/aiofiles/aiofiles/threadpool/utils.pyi index 341396135..afff76d0d 100644 --- a/stubs/aiofiles/aiofiles/threadpool/utils.pyi +++ b/stubs/aiofiles/aiofiles/threadpool/utils.pyi @@ -1,6 +1,11 @@ +from collections.abc import Callable from types import coroutine as coroutine +from typing import TypeVar -def delegate_to_executor(*attrs): ... -def proxy_method_directly(*attrs): ... -def proxy_property_directly(*attrs): ... -def cond_delegate_to_executor(*attrs): ... +_T = TypeVar("_T", bound=type) + +# All these function actually mutate the given type: +def delegate_to_executor(*attrs: str) -> Callable[[_T], _T]: ... +def proxy_method_directly(*attrs: str) -> Callable[[_T], _T]: ... +def proxy_property_directly(*attrs: str) -> Callable[[_T], _T]: ... +def cond_delegate_to_executor(*attrs: str) -> Callable[[_T], _T]: ...