bpo-31163: Added return values to pathlib.Path instance's rename and replace methods. (GH-13582)

* bpo-31163: Added return values to pathlib.Path instance's rename and replace methods.
This commit is contained in:
hui shang 2019-09-11 21:26:49 +08:00 committed by Jason R. Coombs
parent f9b5840fb4
commit 088a09af4b
4 changed files with 30 additions and 11 deletions

View file

@ -1341,20 +1341,24 @@ class Path(PurePath):
def rename(self, target):
"""
Rename this path to the given path.
Rename this path to the given path,
and return a new Path instance pointing to the given path.
"""
if self._closed:
self._raise_closed()
self._accessor.rename(self, target)
return self.__class__(target)
def replace(self, target):
"""
Rename this path to the given path, clobbering the existing
destination if it exists.
destination if it exists, and return a new Path instance
pointing to the given path.
"""
if self._closed:
self._raise_closed()
self._accessor.replace(self, target)
return self.__class__(target)
def symlink_to(self, target, target_is_directory=False):
"""