bpo-31163: Added return values to pathlib.Path instance's rename and replace methods. (GH-13582) (GH-15944)
* bpo-31163: Added return values to pathlib.Path instance's rename and replace methods.
(cherry picked from commit 088a09af4bdeff52b9dedeb7acd1e82069f37d98)
Co-authored-by: hui shang <shangdahao@gmail.com>
diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index 166de8d..ad8f601 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -933,23 +933,32 @@
.. method:: Path.rename(target)
- Rename this file or directory to the given *target*. On Unix, if
- *target* exists and is a file, it will be replaced silently if the user
- has permission. *target* can be either a string or another path object::
+ Rename this file or directory to the given *target*, and return a new Path
+ instance pointing to *target*. On Unix, if *target* exists and is a file,
+ it will be replaced silently if the user has permission. *target* can be
+ either a string or another path object::
>>> p = Path('foo')
>>> p.open('w').write('some text')
9
>>> target = Path('bar')
>>> p.rename(target)
+ PosixPath('bar')
>>> target.open().read()
'some text'
+ .. versionchanged:: 3.8
+ Added return value, return the new Path instance.
+
.. method:: Path.replace(target)
- Rename this file or directory to the given *target*. If *target* points
- to an existing file or directory, it will be unconditionally replaced.
+ Rename this file or directory to the given *target*, and return a new Path
+ instance pointing to *target*. If *target* points to an existing file or
+ directory, it will be unconditionally replaced.
+
+ .. versionchanged:: 3.8
+ Added return value, return the new Path instance.
.. method:: Path.resolve(strict=False)