Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix AiofilesContextManagerTempDir type argument #14349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

poofeg
Copy link

@poofeg poofeg commented Jun 28, 2025

When using aiofiles.tempfile.TemporaryDirectory with AsyncExitStack as shown below:

import asyncio
from contextlib import AsyncExitStack
from typing import reveal_type

from aiofiles.tempfile import TemporaryDirectory


async def main() -> None:
    stack = AsyncExitStack()
    d = await stack.enter_async_context(TemporaryDirectory())
    reveal_type(d)
    await stack.aclose()


if __name__ == '__main__':
    asyncio.run(main())

Mypy reports Revealed type is "aiofiles.tempfile.temptypes.AsyncTemporaryDirectory", but running the code shows: Runtime type is 'str'.

This PR fixes this mismatch.

Copy link
Contributor

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

Copy link
Member

@brianschubert brianschubert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference: https://github.com/Tinche/aiofiles/blob/6fdc25c7812d6738ccf51c5e7d4cd68500053a52/src/aiofiles/tempfile/__init__.py#L326-L328

where self._obj is a tempfile.TemporaryDirectory instance, so self._obj.name is indeed a str (I don't think it can ever be bytes?)

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