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 might have been able to remove the str from there if #28623 wasn't rejected.) I wish I could do this: ssh_client.run(f'/bin/rm {path}') But since my path has a space, that would only be possible if PurePath.__str__ were to use shlex.quote, and put quotes around my path (only if it includes a space). What do you think about that?
This will break any code that pass str(path) to API that doesn't support pathlib. In your case you can introduce a short alias: q = shlex.quote ssh_client.run(f'/bin/rm {q(str(path))}') Or add more convenient helper: def q(path): return shlex.quote(str(path)) ssh_client.run(f'/bin/rm {q(path)}')
"This will break any code that pass str(path) to API that doesn't support pathlib." I don't understand. Can you give a concrete example of code it would break?