GH-73991: Add pathlib.Path.move()#122073
Conversation
Add a `Path.move()` method that moves a file or directory tree and returns a new `Path` instance. This method is similar to `shutil.move()`, except that it doesn't accept a *copy_function* argument, and it doesn't support copying into an existing directory.
This reverts commit a98aed4.
Sorry, something went wrong.
|
Should be ready to review again :-) This isn't quite the last PR in this series. I'll log another to add |
Sorry, something went wrong.
|
Sorry for flip-flopping. I've moved the |
Sorry, something went wrong.
|
I've reviewed the other PR. Do you want me to review this one now or should I wait? |
Sorry, something went wrong.
Sorry for the slow reply - I think it would be best to wait for the other PR to land before reviewing this. |
Sorry, something went wrong.
|
Hey @picnixz, this is ready to review again FYI. Thanks in advance :) |
Sorry, something went wrong.
picnixz
left a comment
There was a problem hiding this comment.
I think it would be good to also have assertions before calling move(). That way you really know how the state of the files change before/after the test (and that way, we are sure that we are in a correct test environment). I did not mark all tests that need this but any test that does self.assertTrue(target.exists()) after moving should do self.assertFalse(target.exists()) before moving (and if the target is to be overwritten, then it should check that it's content changed).
Sorry, something went wrong.
|
I don't understand why we'd make assertions before calling |
Sorry, something went wrong.
I shouldn't make review at 3 AM... Yes, why didn't I think about it. So yes, it's fine (I'm marking my comments as resolved). Sorry Barney for the time loss :( |
Sorry, something went wrong.
Oh now, don't be silly! I really appreciate all your help with this PR and others, I apologise if I came off too strongly in my previous comment. I consider these sorts of discussions a great use of my time :) |
Sorry, something went wrong.
No your comment was definitely legitimate! I also appreciate your review and feedback on my |
Sorry, something went wrong.
picnixz
left a comment
There was a problem hiding this comment.
All good for me! I'll leave the discussion on clubber opened so that you can create a separate issue from the comment if you want.
Sorry, something went wrong.
|
Amazing, thanks so much! I'll get back to your |
Sorry, something went wrong.
Add a
Path.move()method that moves a file or directory tree, and returns a newPathinstance pointing to the target.This method is similar to
shutil.move(), except that it doesn't accept a copy_function argument, and it doesn't check whether the destination is an existing directory.In pathlib's private ABCs,
PathBase.move()uses thecopy()anddelete()methods to move files and directories.📚 Documentation preview 📚: https://cpython-previews--122073.org.readthedocs.build/