-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
GH-73991: Add pathlib.Path.move()
#122073
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
Merged
+225
−4
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
f6d09c0
GH-73991: Add `pathlib.Path.move()`
barneygale 1dc0bfb
Simplify slightly
barneygale f488ff8
Test existing files/directories as destinations.
barneygale ff7746f
rename --> replace
barneygale 29e51f5
Windows test fixes
barneygale 36955ab
Revert "Windows test fixes"
barneygale d595047
Handle existing targets more consistently
barneygale 5de963e
Use generic implementation on ERROR_ACCESS_DENIED.
barneygale e1c0d9e
Expand test coverage, lean into the Windows differences a bit.
barneygale a98aed4
Loosen tests for OSError types.
barneygale 0af6396
Revert "Loosen tests for OSError types."
barneygale 348cabd
Tweaks
barneygale aca70d1
Relax expectations once again.
barneygale aa27f48
skip tests affected by apparent os.replace() inconsistency
barneygale 04b115a
More compatibility experiments.
barneygale be48d2a
Cunningly avoid specifying the problematic cases.
barneygale a5ee60a
Fix moving a file/directory to itself.
barneygale f9219ee
Undo unnecessary change
barneygale 5ad2c1d
Ensure we exit from copytree() when copying directory over itself.
barneygale 46b1fc2
Merge branch 'main' into path-move
barneygale d889dff
Merge branch 'main' into path-move
barneygale 9d92108
Docs tweak
barneygale 92cc785
Set `filename` and `filename2` in error messages.
barneygale b8372aa
Simplify patch
barneygale 8199fd5
Undo changes from GH-122924.
barneygale 175d687
Merge branch 'main' into path-move
barneygale 8182a88
Merge branch 'main' into path-move
barneygale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2024-07-21-02-00-46.gh-issue-73991.pLxdtJ.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add :meth:`pathlib.Path.move`, which moves a file or directory tree. |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just me thinking loud, but do you think we should have a boolean to not overwrite an existing target (in which case, a
FileExistsError
would be raised)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add a
clobber=True
argument, but I think that would be a separate PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have thought of
strict
(strict=False by default, strict=True would raise) orreplace=True
. But we can address this question later. Otherwise, it's just a three liner where users would doif not os.exists(target)
if they want to avoid replacing files.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Clobber" has some currency already, e.g. in
mv --no-clobber
. But yeah, let's discuss later.