Skip to content

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

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

gh-119670: Add force keyword only argument to shlex.quote#148846
jb2170 wants to merge 6 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 about shlex.quote returning "''" for falsey non-str data. This PR and that issue seem independent of each other, that is this PR doesn't need to be held back until that issue 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 😅

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

1 participant