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: Provide method PurePath.quote() that calls shlex.quote
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: cool-RR, pitrou, serhiy.storchaka, zach.ware
Priority: normal Keywords:

Created on 2016-11-28 10:41 by cool-RR, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg281858 - (view) Author: Ram Rachum (cool-RR) * Date: 2016-11-28 10:41
I have a a PurePath object like so:

    path = PurePath('/home/my awesome user/file.txt')

I'm SSHing into a server and I want to remove the file. So I have to do this: 

    ssh_client.run(f'/bin/rm {shlex.quote(str(path))}')
    
Which is really long and ugly. 

I suggested in issue28623 that shlex.quote could just take a Path argument, and in issue28811 that __str__ would use shlex.quote, and it was rejected too. 

My next suggestion: Implement PurePath.quote() method that calls shlex.quote() on the path. What do you think?
msg281859 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-11-28 10:55
Please no. The interface of pathlib is already overburdened. We shouldn't add every function that is applicable to string paths as a Path method.
msg281876 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2016-11-28 13:59
You already have a short, simple, one-line solution, and have had suggestions for shortening it yourself if you absolutely need to do so.  If you can provide proof that this is an extremely common use case (and considering how short the solution already is, it would need to be completely ubiquitous), we might reconsider this, but in the absence of such proof these suggestions are trying to solve a problem that doesn't exist.
History
Date User Action Args
2022-04-11 14:58:40adminsetgithub: 73003
2016-11-28 13:59:16zach.waresetstatus: open -> closed

nosy: + zach.ware
messages: + msg281876

resolution: rejected
stage: resolved
2016-11-28 10:55:25serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg281859
2016-11-28 10:41:50cool-RRsetversions: + Python 3.7, - Python 3.6
2016-11-28 10:41:44cool-RRcreate