Skip to content

[aiofiles] Make AsyncSpooledTemporaryFile.fileno/rollover awaitable - #16719

Merged
srittau merged 1 commit into
python:mainfrom
Dhairya-007:aiofiles-spooled-delegates
Nov 6, 2026
Merged

srittau merged 1 commit into
python:mainfrom
Dhairya-007:aiofiles-spooled-delegates

Conversation

@Dhairya-007

Copy link
Copy Markdown
Contributor

AsyncSpooledTemporaryFile.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]")  [misc]

Both are generated by @delegate_to_executor("fileno", "rollover"), and _make_delegate_method builds an 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()
6
>>> await f.rollover()
None

So they are now async def returning what the delegated SpooledTemporaryFile methods return, which also matches how every other delegated method in this class is already written (close, flush, isatty, tell, ...).

Both names are already in @tests/stubtest_allowlist.txt, under the comment that covers exactly this case — "These all delegate using *args,**kwargs, but stubs use signature of method they are being delegated to" — so stubtest is unaffected.

The Generator import is now unused and dropped. Checked with mypy --strict.

`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."
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau
srittau merged commit 13ffe24 into python:main Nov 6, 2026
74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants