From 0fc159f235604f91fda0702e6fe435ff6b60c8f9 Mon Sep 17 00:00:00 2001 From: dhairya05 Date: Fri, 6 Nov 2026 21:40:02 +0530 Subject: [PATCH] [aiofiles] Make AsyncSpooledTemporaryFile.fileno/rollover awaitable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `fileno` and `rollover` were declared as plain methods returning `Generator[Incomplete]`, so awaiting them — the only way to call them — was a type error: await f.fileno() # error: Incompatible types in "await" (actual type # "Generator[Any, None, None]", expected type "Awaitable[Any]") Both are generated by `@delegate_to_executor("fileno", "rollover")`, and `_make_delegate_method` builds `async def method(self, *args, **kwargs)` that awaits `run_in_executor`. Verified against aiofiles 25.1.0: >>> inspect.iscoroutinefunction(AsyncSpooledTemporaryFile.fileno) True >>> await f.fileno(), await f.rollover() (6, None) Declared them `async def` returning the types the delegated `SpooledTemporaryFile` methods return, matching how every other delegated method in this class is already written. Both are already in the stubtest allowlist, which exists for exactly this case: "These all delegate using *args,**kwargs, but stubs use signature of method they are being delegated to." --- stubs/aiofiles/aiofiles/tempfile/temptypes.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi b/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi index b6f05e13c7ce..e709d2c9996a 100644 --- a/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi +++ b/stubs/aiofiles/aiofiles/tempfile/temptypes.pyi @@ -1,6 +1,6 @@ from _typeshed import Incomplete, OpenBinaryMode, ReadableBuffer from asyncio import AbstractEventLoop -from collections.abc import Generator, Iterable +from collections.abc import Iterable from concurrent.futures import Executor from tempfile import TemporaryDirectory from typing import TypeVar @@ -15,8 +15,8 @@ from aiofiles.threadpool.utils import ( _T = TypeVar("_T") class AsyncSpooledTemporaryFile(AsyncBase[_T]): - def fileno(self) -> Generator[Incomplete]: ... - def rollover(self) -> Generator[Incomplete]: ... + async def fileno(self) -> int: ... + async def rollover(self) -> None: ... async def close(self) -> None: ... async def flush(self) -> None: ... async def isatty(self) -> bool: ...