Title: Return destination path in Path.rename and Path.replace
Type: enhancement Stage:
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:

Created on 2017-08-09 15:32 by albertogomcas, last changed 2017-08-09 18:14 by r.david.murray.

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-08-09 18:14:33r.david.murraysetnosy: + r.david.murray
messages: + msg300027
2017-08-09 15:32:24albertogomcascreate