| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
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 copy_into() and move_into(), and then post to discuss.python.org about perhaps eliminating some/all of the ignore_errors, on_error and ignore arguments to delete() and copy(). |
Sorry, something went wrong.
|
Sorry for flip-flopping. I've moved the copy() changes into their own PR (#122924) so I'll mark this as a draft once again (-: |
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.
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.
| Added return value, return the new :class:`!Path` instance. | ||
|
|
||
|
|
||
| .. method:: Path.move(target) |
There was a problem hiding this comment.
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)?
Sorry, something went wrong.
There was a problem hiding this comment.
We could add a clobber=True argument, but I think that would be a separate PR.
Sorry, something went wrong.
There was a problem hiding this comment.
I would have thought of strict (strict=False by default, strict=True would raise) or replace=True. But we can address this question later. Otherwise, it's just a three liner where users would do if not os.exists(target) if they want to avoid replacing files.
Sorry, something went wrong.
There was a problem hiding this comment.
"Clobber" has some currency already, e.g. in mv --no-clobber. But yeah, let's discuss later.
Sorry, something went wrong.
|
I don't understand why we'd make assertions before calling move() - we already know the state of the test directory (self.base) because it's configured to our specification in setUp(). If we applied this logic consistently we'd need to adjust almost every test case in DummyPathTest and PathTest! |
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 fnmatch issues / PRs! |
Sorry, something went wrong.
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 fnmatch stuff shortly! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Add a Path.move() method that moves a file or directory tree, and returns a new Path instance 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 the copy() and delete() methods to move files and directories.
📚 Documentation preview 📚: https://cpython-previews--122073.org.readthedocs.build/