Skip to content

Commit f97e42e

Browse files
authored
bpo-40833: Clarify Path.rename doc-string regarding relative paths (pythonGH-20554)
1 parent 6a412c9 commit f97e42e

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

Doc/library/pathlib.rst

+8
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,10 @@ call fails (for example because the path doesn't exist).
10081008
>>> target.open().read()
10091009
'some text'
10101010

1011+
The target path may be absolute or relative. Relative paths are interpreted
1012+
relative to the current working directory, *not* the directory of the Path
1013+
object.
1014+
10111015
.. versionchanged:: 3.8
10121016
Added return value, return the new Path instance.
10131017

@@ -1018,6 +1022,10 @@ call fails (for example because the path doesn't exist).
10181022
instance pointing to *target*. If *target* points to an existing file or
10191023
directory, it will be unconditionally replaced.
10201024

1025+
The target path may be absolute or relative. Relative paths are interpreted
1026+
relative to the current working directory, *not* the directory of the Path
1027+
object.
1028+
10211029
.. versionchanged:: 3.8
10221030
Added return value, return the new Path instance.
10231031

Lib/pathlib.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -1366,17 +1366,26 @@ def link_to(self, target):
13661366

13671367
def rename(self, target):
13681368
"""
1369-
Rename this path to the given path,
1370-
and return a new Path instance pointing to the given path.
1369+
Rename this path to the target path.
1370+
1371+
The target path may be absolute or relative. Relative paths are
1372+
interpreted relative to the current working directory, *not* the
1373+
directory of the Path object.
1374+
1375+
Returns the new Path instance pointing to the target path.
13711376
"""
13721377
self._accessor.rename(self, target)
13731378
return self.__class__(target)
13741379

13751380
def replace(self, target):
13761381
"""
1377-
Rename this path to the given path, clobbering the existing
1378-
destination if it exists, and return a new Path instance
1379-
pointing to the given path.
1382+
Rename this path to the target path, overwriting if that path exists.
1383+
1384+
The target path may be absolute or relative. Relative paths are
1385+
interpreted relative to the current working directory, *not* the
1386+
directory of the Path object.
1387+
1388+
Returns the new Path instance pointing to the target path.
13801389
"""
13811390
self._accessor.replace(self, target)
13821391
return self.__class__(target)

0 commit comments

Comments
 (0)