gh-109503: Fix document for shutil.move on usage of os.rename since it's inaccurate
#109507
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
gh-109503: Fix document for
shutil.moveon usage ofos.renamesince it's inaccurateThe document/docstring for
shutil.movestates:which seems to be incorrect. The actual behavior shows below:
srcandtargetare on the same filesystem,os.renameis preferred, which is an atomic operation.os.renamefails due to some reason (e.g. permission denied), thenshutil.movewill silently fallback to nonatomiccopy+remove.This
fallbackbehavior is crucial in case atomic operation matters. It creates false statement that an operation must be atomic, while in fact it is non-atomic in some cases. This behavior can be found in source code here.For example
Given all following dirs and files on the SAME filesystem
When the userA calls:
Based on current doc, user expects that the move must be atomic since both files are on the same filesystem. But in fact, this operation will fall back to
copy+delsilently, which is not atomic.📚 Documentation preview 📚: https://cpython-previews--109507.org.readthedocs.build/