mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
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:
parent
a4e773c540
commit
95352dcb93
4 changed files with 148 additions and 153 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue