Skip to content

[aiofiles] aiofiles.tempfile.NamedTemporaryFile.name should probably be a str #13551

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
sashkent3 opened this issue Feb 27, 2025 · 3 comments · May be fixed by #13621
Open

[aiofiles] aiofiles.tempfile.NamedTemporaryFile.name should probably be a str #13551

sashkent3 opened this issue Feb 27, 2025 · 3 comments · May be fixed by #13621
Labels
stubs: false positive Type checkers report false errors

Comments

@sashkent3
Copy link
Contributor

sashkent3 commented Feb 27, 2025

When using aiofiles like this:

from aiofiles.tempfile import NamedTemporaryFile


async def main():
    async with NamedTemporaryFile() as f:
        print(f.name)

f.name is reported to be a FileDescriptorOrPath. It should probably be a str instead because that's how it is for the stdlib's tempfile.NamedTemporaryFile and that's the whole point of a named temporary file.

@srittau srittau added the stubs: false positive Type checkers report false errors label Feb 27, 2025
@srittau
Copy link
Collaborator

srittau commented Feb 27, 2025

Any improvements welcome!

@larsott1
Copy link

larsott1 commented Mar 4, 2025

I tested this with aiofiles 24.1.0 on Python 3.11.10 (Windows), and f.name correctly returns str. This issue might have been fixed in a recent update. Could you confirm which aiofiles version you were using?

@sashkent3
Copy link
Contributor Author

I'm on aiofiles 24.1.0 on Python 3.13.2 (Linux) and the issue persists. I understand that the type of f.name is str at runtime, but can you confirm the revealed static type with:

from typing import reveal_type

from aiofiles.tempfile import NamedTemporaryFile


async def main():
    async with NamedTemporaryFile() as f:
        reveal_type(f.name)

The issue stems from:

def name(self) -> FileDescriptorOrPath: ...
so I'm doubtful it's fixed.

@sobolevn sobolevn linked a pull request Mar 12, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants