Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path.replace and Path.rename naming, behavior and documentation #75337

Closed
albertogomcas mannequin opened this issue Aug 9, 2017 · 2 comments
Closed

Path.replace and Path.rename naming, behavior and documentation #75337

albertogomcas mannequin opened this issue Aug 9, 2017 · 2 comments
Labels
docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@albertogomcas
Copy link
Mannequin

albertogomcas mannequin commented Aug 9, 2017

BPO 31154
Nosy @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2017-08-09.13:30:18.770>
created_at = <Date 2017-08-09.08:07:01.667>
labels = ['type-bug', 'library', 'docs']
title = 'Path.replace and Path.rename naming, behavior and documentation'
updated_at = <Date 2017-08-09.13:30:18.768>
user = 'https://bugs.python.org/albertogomcas'

bugs.python.org fields:

activity = <Date 2017-08-09.13:30:18.768>
actor = 'r.david.murray'
assignee = 'docs@python'
closed = True
closed_date = <Date 2017-08-09.13:30:18.770>
closer = 'r.david.murray'
components = ['Documentation', 'Library (Lib)']
creation = <Date 2017-08-09.08:07:01.667>
creator = 'albertogomcas'
dependencies = []
files = []
hgrepos = []
issue_num = 31154
keywords = []
message_count = 2.0
messages = ['299976', '300001']
nosy_count = 3.0
nosy_names = ['r.david.murray', 'docs@python', 'albertogomcas']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue31154'
versions = ['Python 3.6']

@albertogomcas
Copy link
Mannequin Author

albertogomcas mannequin commented Aug 9, 2017

I find the naming of Path.replace quite unfortunate, coming from the os.path and basestring mindset, the expectation would be that it would change some substring by another substring in the Path instance. Instead, it _moves_ the file indicated by the Path object in the file system. Most of the methods of Path have no effect in the filesystem, and we have here one with a slightly misleading name which goes and moves your files around.

Practically the same operation is done with Path.rename, which is less surprising since it matches popular OS commands/UIs (ren, Rename).

IMHO Path.replace should not exist as is and a keyword modifier (silent?) for Path.rename toggles between the minor behavior differences of the two.

Additionally:

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, after the call the Path instance keeps "pointing" to the previous (and quite likely now useless) path. Returning the new path would be another reasonable option. In any case, I think the documentation should mention this behavior explicitly.

And, while we are at it, having implemented the relatively dangerous replace/rename (along with convenience shorcuts for reading, writing, opening...), why was a Path.copy not included?

@albertogomcas albertogomcas mannequin assigned docspython Aug 9, 2017
@albertogomcas albertogomcas mannequin added docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 9, 2017
@bitdancer
Copy link
Member

Both the replace and rename functions will remain in the API, as they mirror the os module, not the os itself. I agree that the naming is unfortunate, but it has the weight of history behind it, so we are stuck with it. bpo-24229 rejected adding a copy method.

Having replace and rename return a value strikes me as a good idea. Please open a separate issue with that enhancement proposal, and nosy 'pitrou', who is the author of the pathlib module.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant