Skip to content

[3.8] bpo-40833: Clarify Path.rename doc-string regarding relative paths (GH-20554) #22515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand Down
19 changes: 14 additions & 5 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,8 +1353,13 @@ def link_to(self, target):

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()
Expand All @@ -1363,9 +1368,13 @@ def rename(self, 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.
"""
if self._closed:
self._raise_closed()
Expand Down