bpo-40833: Clarify Path.rename doc-string regarding relative paths (GH-20554)

(cherry picked from commit f97e42ef4d)

Co-authored-by: Ram Rachum <ram@rachum.com>
This commit is contained in:
Miss Skeleton (bot) 2020-10-03 03:11:39 -07:00 committed by GitHub
parent cfed534333
commit 4b982e0dd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 5 deletions

View File

@ -954,6 +954,10 @@ call fails (for example because the path doesn't exist).
>>> target.open().read()
'some text'
The target path may be absolute or relative. Relative paths are interpreted
relative to the current working directory, *not* the directory of the Path
object.
.. versionchanged:: 3.8
Added return value, return the new Path instance.
@ -964,6 +968,10 @@ call fails (for example because the path doesn't exist).
instance pointing to *target*. If *target* points to an existing file or
directory, it will be unconditionally replaced.
The target path may be absolute or relative. Relative paths are interpreted
relative to the current working directory, *not* the directory of the Path
object.
.. versionchanged:: 3.8
Added return value, return the new Path instance.

View File

@ -1353,8 +1353,13 @@ class Path(PurePath):
def rename(self, target):
"""
Rename this path to the given path,
and return a new Path instance pointing to the given path.
Rename this path to the target path.
The target path may be absolute or relative. Relative paths are
interpreted relative to the current working directory, *not* the
directory of the Path object.
Returns the new Path instance pointing to the target path.
"""
if self._closed:
self._raise_closed()
@ -1363,9 +1368,13 @@ class Path(PurePath):
def replace(self, target):
"""
Rename this path to the given path, clobbering the existing
destination if it exists, and return a new Path instance
pointing to the given path.
Rename this path to the target path, overwriting if that path exists.
The target path may be absolute or relative. Relative paths are
interpreted relative to the current working directory, *not* the
directory of the Path object.
Returns the new Path instance pointing to the target path.
"""
if self._closed:
self._raise_closed()