Repository navigation
[aiofiles] Make AsyncSpooledTemporaryFile.fileno/rollover awaitable - #16719
Merged
Merged
Conversation
`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."
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
srittau
approved these changes
Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AsyncSpooledTemporaryFile.filenoand.rolloverwere declared as plain methods returningGenerator[Incomplete], so awaiting them — the only way to call them — was a type error:Both are generated by
@delegate_to_executor("fileno", "rollover"), and_make_delegate_methodbuilds anasync def method(self, *args, **kwargs)that awaitsrun_in_executor. Verified against aiofiles 25.1.0:So they are now
async defreturning what the delegatedSpooledTemporaryFilemethods 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
Generatorimport is now unused and dropped. Checked withmypy --strict.