Skip to content

[aiofiles] Fix NamedTemporaryFile name type - #16162

Open
nightcityblade wants to merge 1 commit into
python:mainfrom
nightcityblade:fix/issue-13551
Open

[aiofiles] Fix NamedTemporaryFile name type#16162
nightcityblade wants to merge 1 commit into
python:mainfrom
nightcityblade:fix/issue-13551

Conversation

@nightcityblade

Copy link
Copy Markdown
Contributor

Fixes #13551

What problem this solves

aiofiles.tempfile.NamedTemporaryFile() currently exposes name as the broad FileDescriptorOrPath type, unlike the named temporary-file API it wraps.

Why this change

The general async file wrappers must retain their broad name type because aiofiles.open() accepts file descriptors and path-like values. This adds private named-temporary-file wrapper types that narrow only NamedTemporaryFile() results to str.

User impact

Type checkers now accept string-specific operations on file.name inside both binary and text NamedTemporaryFile() context managers.

Evidence

  • Added regression assertions for default binary and text modes.
  • source .venv/bin/activate && python tests/runtests.py stubs/aiofiles --run-stubtest
    • pre-commit, structure, Pyright, ty, pyrefly, mypy, stubtest, and both regression suites passed.

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

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

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.

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

1 participant