Skip to content

gh-119670: Add force keyword only argument to shlex.quote#148846

Open
jb2170 wants to merge 10 commits intopython:mainfrom
jb2170:shlex-quote-force
Open

gh-119670: Add force keyword only argument to shlex.quote#148846
jb2170 wants to merge 10 commits intopython:mainfrom
jb2170:shlex-quote-force

Conversation

@jb2170
Copy link
Copy Markdown
Contributor

@jb2170 jb2170 commented Apr 21, 2026

Closes #119670
Supersedes my out-of-date PR #119674

We use force instead of always as a word more consistent with other programming jargon (like in rm -f the f is for 'force') as discussed

Commits

  • ddbe3a5: Add base implementation.
  • 0e722d6: Make shlex.quote's kwargs kwargs-only. Backwards compatible. There are propositions to add a single-quote-double-quote switch, which I'm ambivalent about, but to future-proof against hiccups of people passing force as a positional and it ending up being used as the wrong kwarg, we make the kwargs kwargs-only, eg like json.loads.
  • fd4af18: Add tests. I've tried to be pretty thorough. Their purposes are commented on.
  • 78b6f3b: Update docs. Contains explanation and examples.
  • 762999d: Add blurb entry.
  • 2a301a5: Add whatsnew entry.

As mentioned I'm also going to open an issue a discussion thread about shlex.quote returning "''" for falsey non-str data. This PR and that discussion seem independent of each other, that is this PR doesn't need to be held back until that discussion is addressed.


📚 Documentation preview 📚: https://cpython-previews--148846.org.readthedocs.build/

jb2170 added 5 commits April 21, 2026 04:41
There are propositions to add a single-quote-double-quote switch
(pythongh-90630), so to avoid hiccups of people passing `force` as a
positional and it being used for the single-double switch, we make
kwargs kwargs-only.
Test special cases of strings that don't need quoting, do need quoting,
do use `force`, don't use `force` etc. I've tried to be exhaustive.
@jb2170 jb2170 requested a review from AA-Turner as a code owner April 21, 2026 18:43
@jb2170
Copy link
Copy Markdown
Contributor Author

jb2170 commented Apr 21, 2026

@vstinner pong 😅

Copy link
Copy Markdown
Member

@johnslavik johnslavik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment thread Lib/shlex.py Outdated
Comment thread Lib/test/test_shlex.py Outdated
Comment thread Lib/test/test_shlex.py Outdated
@johnslavik
Copy link
Copy Markdown
Member

johnslavik commented Apr 22, 2026

Hmm I also have a hunch that this might be worth calling out in What's New. Nvm it's already there, great job 🚀

jb2170 and others added 4 commits April 22, 2026 18:59
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
The comments for why these tests exist can always be found in the git history

Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
Intended for another branch shlex-quote-typeerror

Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shlex.quote: Add 'always' keyword argument

2 participants