Skip to content

gh-142389: Add support for backtick colorisation in argparse help text#149375

Merged
hugovk merged 8 commits intopython:mainfrom
hugovk:3.15-argparse-help-backticks
May 4, 2026
Merged

gh-142389: Add support for backtick colorisation in argparse help text#149375
hugovk merged 8 commits intopython:mainfrom
hugovk:3.15-argparse-help-backticks

Conversation

@hugovk
Copy link
Copy Markdown
Member

@hugovk hugovk commented May 4, 2026

#142390 added support for displaying text enclosed in backticks in colour for the help description and epilogue.

This PR adds it for individual help.

Also add backticks to python -m test --help:

image

Will add to other stdlib CLIs in a followup.

@hugovk hugovk requested a review from savannahostrowski as a code owner May 4, 2026 18:13
@hugovk hugovk added the stdlib Standard Library Python modules in the Lib/ directory label May 4, 2026
@hugovk hugovk requested a review from AA-Turner as a code owner May 4, 2026 18:13
@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented May 4, 2026

Documentation build overview

📚 cpython-previews | 🛠️ Build #32534304 | 📁 Comparing 634cfe6 against main (10f950c)

  🔍 Preview build  

3 files changed
± library/argparse.html
± whatsnew/3.15.html
± whatsnew/changelog.html

Copy link
Copy Markdown
Member

@savannahostrowski savannahostrowski left a comment

Choose a reason for hiding this comment

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

I think there's one edge case here that we haven't considered...and should before extending this to help text. Poking around on GitHub, flake8 uses double backticks to denote code in help text (I also found at least one instance of this in pytest as well but it's not as pervasive). So, right now, with these changes users would see something like this, where there are funky stray backticks and incorrect colouring:

Image

I think if we apply the new regex, update the docs and add a test or two, that should have us covered.

Other than that, I think this looks good. My preference would be to land this feature and then land application of backticks in a separate PR though (i.e. we can leave libregrtest changes for another PR?)

Comment thread Lib/argparse.py Outdated
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 4, 2026

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@hugovk
Copy link
Copy Markdown
Member Author

hugovk commented May 4, 2026

Updated docs, docstring and added tests.

Removed the regrtest change, will be in a followup with other stdlib stuff.

I have made the requested changes; please review again.

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 4, 2026

Thanks for making the requested changes!

@savannahostrowski: please review the changes made to this pull request.

@bedevere-app bedevere-app Bot requested a review from savannahostrowski May 4, 2026 21:28
Copy link
Copy Markdown
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

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

We apply color before width is calculated, leading to some odd line breaks.

With NO_COLOR:

Image

Whereas with color:

Image

@hugovk
Copy link
Copy Markdown
Member Author

hugovk commented May 4, 2026

We apply color before width is calculated, leading to some odd line breaks.

There's a separate issue for this somewhere, and maybe even a PR?

@hugovk
Copy link
Copy Markdown
Member Author

hugovk commented May 4, 2026

My preference would be to land this feature and then land application of backticks in a separate PR though (i.e. we can leave libregrtest changes for another PR?)

Please see PR #149384.

Comment thread Doc/whatsnew/3.15.rst Outdated
Comment thread Lib/test/test_argparse.py
Copy link
Copy Markdown
Member

@savannahostrowski savannahostrowski left a comment

Choose a reason for hiding this comment

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

Sweeeeet! :shipit: Thank Hugo!

@hugovk hugovk enabled auto-merge (squash) May 4, 2026 22:43
@hugovk hugovk merged commit ffe050a into python:main May 4, 2026
55 of 56 checks passed
@hugovk hugovk deleted the 3.15-argparse-help-backticks branch May 4, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stdlib Standard Library Python modules in the Lib/ directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants