GH-127381: pathlib ABCs: remove PathBase.move() and move_into() (#128337)

These methods combine `_delete()` and `copy()`, but `_delete()` isn't part
of the public interface, and it's unlikely to be added until the pathlib
ABCs are made official, or perhaps even later.
This commit is contained in:
Barney Gale 2025-01-04 12:53:51 +00:00 committed by GitHub
parent a4e773c540
commit 95352dcb93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 148 additions and 153 deletions

View file

@ -573,30 +573,3 @@ class PathBase(PurePathBase):
return self.copy(target, follow_symlinks=follow_symlinks,
dirs_exist_ok=dirs_exist_ok,
preserve_metadata=preserve_metadata)
def _delete(self):
"""
Delete this file or directory (including all sub-directories).
"""
raise NotImplementedError
def move(self, target):
"""
Recursively move this file or directory tree to the given destination.
"""
target = self.copy(target, follow_symlinks=False, preserve_metadata=True)
self._delete()
return target
def move_into(self, target_dir):
"""
Move this file or directory tree into the given existing directory.
"""
name = self.name
if not name:
raise ValueError(f"{self!r} has an empty name")
elif isinstance(target_dir, PathBase):
target = target_dir / name
else:
target = self.with_segments(target_dir, name)
return self.move(target)