This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Return destination path in Path.rename and Path.replace
Type: enhancement Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: albertogomcas, berker.peksag, cheryl.sabella, docs@python, jaraco, pitrou, r.david.murray
Priority: normal Keywords: easy, patch

Created on 2017-08-09 15:32 by albertogomcas, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4055 closed keichiri, 2017-10-20 00:27
PR 13582 merged shangdahao, 2019-05-26 08:55
PR 15944 merged miss-islington, 2019-09-11 13:27
Messages (5)
msg300019 - (view) Author: Alberto Gomez Casado (albertogomcas) Date: 2017-08-09 15:32
Extracted from issue31154

Both calls lack any kind of return, which leads me to expect after a rename/replace the Path instance would be changed to the new path. This is not the case (reading the PEP I have seen Path instances are kind of immutable), after the call the Path instance keeps "pointing" to the previous (and quite likely now useless) path. 

Returning the new path would be a reasonable option. In any case, I think the documentation should mention this behavior explicitly.
msg300027 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-08-09 18:14
I agree.  The normal python convention is that an immutable object returns the new value when an operation "changes" it, while a mutable object returns None.  It seems like replace and rename should follow this convention (and that it would also be convenient).
msg342970 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-05-21 01:16
I've closed the original pull request as the Github user account that created it no longer exists.
msg351865 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2019-09-11 13:26
New changeset 088a09af4bdeff52b9dedeb7acd1e82069f37d98 by Jason R. Coombs (hui shang) in branch 'master':
bpo-31163: Added return values to pathlib.Path instance's rename and replace methods. (GH-13582)
https://github.com/python/cpython/commit/088a09af4bdeff52b9dedeb7acd1e82069f37d98
msg351892 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2019-09-11 14:12
New changeset cbd7b2a399a8ff2ed9994c380b07ef598892b6b1 by Jason R. Coombs (Miss Islington (bot)) in branch '3.8':
bpo-31163: Added return values to pathlib.Path instance's rename and replace methods. (GH-13582) (GH-15944)
https://github.com/python/cpython/commit/cbd7b2a399a8ff2ed9994c380b07ef598892b6b1
History
Date User Action Args
2022-04-11 14:58:49adminsetgithub: 75346
2019-09-11 14:23:08jaracosetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.9
2019-09-11 14:12:56jaracosetmessages: + msg351892
2019-09-11 13:27:02miss-islingtonsetpull_requests: + pull_request15578
2019-09-11 13:26:52jaracosetnosy: + jaraco
messages: + msg351865
2019-05-26 08:55:00shangdahaosetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request13489
2019-05-21 01:16:02cheryl.sabellasetversions: + Python 3.8, - Python 3.6
nosy: + berker.peksag, cheryl.sabella

messages: + msg342970

keywords: + easy, - patch
stage: patch review -> needs patch
2017-10-20 00:27:58keichirisetkeywords: + patch
stage: patch review
pull_requests: + pull_request4024
2017-08-09 18:14:33r.david.murraysetnosy: + r.david.murray
messages: + msg300027
2017-08-09 15:32:24albertogomcascreate