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

Created on 2017-08-09 15:32 by albertogomcas, last changed 2019-05-26 08:55 by shangdahao.

Pull Requests
URL Status Linked Edit
PR 4055 closed keichiri, 2017-10-20 00:27
PR 13582 open shangdahao, 2019-05-26 08:55
Messages (3)
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.
Date User Action Args
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