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

Created on 2017-08-09 15:32 by albertogomcas, last changed 2017-10-20 00:27 by keichiri.

Pull Requests
URL Status Linked Edit
PR 4055 open keichiri, 2017-10-20 00:27
Messages (2)
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).
Date User Action Args
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