X Tutup
The Wayback Machine - https://web.archive.org/web/20250609150317/https://github.com/python/cpython/issues/94543
Skip to content

Clarification on how to clean up tempfile.mkstemp #94543

Open
@jugmac00

Description

@jugmac00

Documentation

On tempfile.mkstemp's documentation you can read:

Unlike TemporaryFile(), the user of mkstemp() is responsible for deleting the temporary file when done with it.

mkstemp() returns a tuple containing an OS-level handle to an open file (as would be returned by os.open()) and the absolute pathname of that file, in that order.

After seeing the os.open I thought it would be enough to use os.close on the file handle - which is obviously not the case.

I would suggest to update the first paragraph to something like this:

Unlike TemporaryFile(), the user of mkstemp() is responsible for deleting the temporary file with e.g. os.remove when done with it.

In my perfect world, this paragraph would even briefly mention whether a os.close is necessary before a os.remove, but I am aware the documentation should be kept succint.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup