-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
Make pathlib.PurePath.__str__ use shlex.quote #72997
Comments
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:
Which is really long and ugly. (I might have been able to remove the str from there if bpo-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))
|
"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? |
open(str(path)) |
I understand now, you're completely right. This change would break the entire world :) |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: