FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-119670: Add `force` keyword only argument to `shlex.quote` by jb2170 · Pull Request #148846 · python/cpython · GitHub

Repository navigation

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

Merged
vstinner merged 17 commits into
python:mainfrom
jb2170:shlex-quote-force
Jun 4, 2026
Merged

vstinner merged 17 commits into
python:mainfrom
jb2170:shlex-quote-force

Conversation

jb2170 commented Apr 21, 2026 •
edited
Loading

Copy link
Copy Markdown
Contributor

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 commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

@vstinner pong 😅

johnslavik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks!

Comment thread Lib/shlex.py Outdated
Comment thread Lib/test/test_shlex.py Outdated
Comment thread Lib/test/test_shlex.py Outdated

johnslavik commented Apr 22, 2026 •
edited
Loading

Copy link
Copy Markdown
Member

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 commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

Looks ready (for review again?) to me 😎

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM.

@picnixz: Do you want to double check? You reviewed the previous PR gh-119674.

picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Minor tweaks but please add more tets with quotes inside.

Comment thread Doc/library/shlex.rst Outdated
Comment thread Doc/library/shlex.rst Outdated
Comment thread Doc/library/shlex.rst
Comment thread Doc/whatsnew/3.15.rst Outdated
Comment thread Lib/shlex.py Outdated
Comment thread Lib/shlex.py Outdated
Comment thread Lib/shlex.py Outdated
Comment thread Lib/test/test_shlex.py
jb2170 force-pushed the shlex-quote-force branch from a9e06cd to e7bf496 Compare April 28, 2026 07:44

picnixz commented Apr 28, 2026

Copy link
Copy Markdown
Member

Please avoid force-pushing. It's extremely hard to make reviews otherwise.

jb2170 force-pushed the shlex-quote-force branch from e7bf496 to e3d9b05 Compare April 28, 2026 08:38

jb2170 commented Apr 28, 2026 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

Sorry for the force pushes but the 'commit suggestions' commits on GitHub came through as CRLF formatted instead of LF. I don't know if that's a GitHub Microsoft issue, or your IDE settings, or I need to git config autocrlf but hey I got there in the end.

$ git log d000ccd...e3d9b05 is what has changed, addressing the review. The only change I disagreed with is the wording of the .. versionadded. The existing one seems to be worded more similarly to the others.

picnixz commented Apr 28, 2026

Copy link
Copy Markdown
Member

I think it's a GH issue because other reviews had the same issue...

jb2170 commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

Ready

picnixz self-requested a review April 28, 2026 15:30

jb2170 commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

@picnixz 30 day courtesy ping 👀

Comment thread Lib/shlex.py Outdated
jb2170 requested a review from picnixz June 3, 2026 01:00

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@jb2170: Please move the "What's New in Python" documentation as I explained in my comment below.

Comment thread Doc/whatsnew/3.15.rst Outdated
jb2170 added 3 commits June 3, 2026 13:59
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 and others added 13 commits June 3, 2026 13: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>
…view

Show off the default behavior as `force=False`
Try not to use don't and we're and should've etc apostrophes.
Add test to ensure string with single quote inside it (without which the
string wouldn't need quoting) is quoted even though `force=False`.
jb2170 force-pushed the shlex-quote-force branch from 7fa8a7a to a030aa4 Compare June 3, 2026 12:59

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32972607 | 📁 Comparing 7781ca0 against main (0b9146e)

  🔍 Preview build  

161 files changed · + 5 added · ± 156 modified

+ Added

± Modified

jb2170 commented Jun 3, 2026 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

Really sorry for the rebase ffs, worst PR ever! 😭
I normally rebase instead of merge. I thought merging main would cause this exact issue but nope the other way round
$ git range-diff d206d42..7fa8a7a 6453065..a030aa4 shows everything is the same before and after the rebase, there's nothing sneaky going on

jb2170 requested a review from johnslavik June 3, 2026 13:36
vstinner dismissed johnslavik’s stale review June 4, 2026 09:04

@johnslavik's review has been addressed.

vstinner merged commit ae507e3 into python:main Jun 4, 2026
52 checks passed

vstinner commented Jun 4, 2026

Copy link
Copy Markdown
Member

Merged. Thanks for your contribution.

jb2170 deleted the shlex-quote-force branch June 4, 2026 10:59
philthompson10 pushed a commit to philthompson10/cpython that referenced this pull request Jun 17, 2026
…ython#148846)

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.

Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shlex.quote: Add force keyword argument

4 participants


Back | FazBrowse Home | New Git URL