diff options
author | Miss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-10-03 03:44:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-03 13:44:14 +0300 |
commit | ef7b937b8fe94f4c59dfcbe7567c3ca76097a41d (patch) | |
tree | ace8fe385603164719e5fb59094dd392ca112ca8 | |
parent | a0f2b664335eb689abdecc677e09a193f503af59 (diff) | |
download | cpython-git-ef7b937b8fe94f4c59dfcbe7567c3ca76097a41d.tar.gz |
[3.9] bpo-40833: Clarify Path.rename doc-string regarding relative paths (GH-20554)
(cherry picked from commit f97e42ef4d97dee64f45ed65170a6e77c8e46fdf)
Co-authored-by: Ram Rachum <ram@rachum.com>
-rw-r--r-- | Doc/library/pathlib.rst | 8 | ||||
-rw-r--r-- | Lib/pathlib.py | 19 |
2 files changed, 22 insertions, 5 deletions
diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 23486b6250..9526a03b05 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -1008,6 +1008,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. @@ -1018,6 +1022,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. diff --git a/Lib/pathlib.py b/Lib/pathlib.py index babc443dd3..147be2ff0d 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -1366,17 +1366,26 @@ 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. """ 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, 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. """ self._accessor.replace(self, target) return self.__class__(target) |