Skip to content

os.rename documentation about atomic replace misleading #143909

@b-jonas0

Description

@b-jonas0

The documentation about os.rename https://docs.python.org/3/library/os.html#os.rename says the following about Unix:

If successful, the renaming will be an atomic operation (this is a POSIX requirement).

But this sentence is misleading. The rename call is atomic only in that the new filename (given by the dst parameter) will always point to either the old file or new file, with no intermediate state. In particular, if you replace an existing file name, then there won't be an observable state when that file name appears deleted. The rename does not act atomically on the old and new filenames together, as in it may happen that both the old name and new name could point to the same file at the same time. I don't think there was ever a requirement for rename to be atomic in the latter sense.

I'm not sure what the best phrasing for the documentation would be. Perhaps something like this:

The new filename dst is updated atomically (this is a POSIX requirement).

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirpendingThe issue will be closed if no feedback is provided

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions