]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40833: Clarify Path.rename doc-string regarding relative paths (GH-20554)
authorRam Rachum <ram@rachum.com>
Sat, 3 Oct 2020 09:52:13 +0000 (12:52 +0300)
committerGitHub <noreply@github.com>
Sat, 3 Oct 2020 09:52:13 +0000 (12:52 +0300)
Doc/library/pathlib.rst
Lib/pathlib.py

index 23486b625072f36c31db47a62e83d0420970e42e..9526a03b053986c1b4a7ae38560c71b42a385dd0 100644 (file)
@@ -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.
 
index babc443dd3b30435817b23d49e65707f5b05f290..147be2ff0dddfccba0a7969140eafbffc1cfedbe 100644 (file)
@@ -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)