Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Merged
hugovk merged 8 commits into
python:mainpython/cpython:mainfrom
hugovk:3.15-argparse-help-backtickshugovk/cpython:3.15-argparse-help-backticksCopy head branch name to clipboard
May 4, 2026
Merged

gh-142389: Add support for backtick colorisation in argparse help text#149375
hugovk merged 8 commits into
python:mainpython/cpython:mainfrom
hugovk:3.15-argparse-help-backtickshugovk/cpython:3.15-argparse-help-backticksCopy head branch name to clipboard

Conversation

@hugovk

@hugovk hugovk commented May 4, 2026

Copy link
Copy Markdown
Member

#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

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

Copy link
Copy Markdown

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

@savannahostrowski savannahostrowski 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.

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

bedevere-app Bot commented May 4, 2026

Copy link
Copy Markdown

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

@hugovk

hugovk commented May 4, 2026

Copy link
Copy Markdown
Member Author

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

bedevere-app Bot commented May 4, 2026

Copy link
Copy Markdown

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

@StanFromIreland StanFromIreland 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.

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

With NO_COLOR:

Image

Whereas with color:

Image

@hugovk

hugovk commented May 4, 2026

Copy link
Copy Markdown
Member Author

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

hugovk commented May 4, 2026

Copy link
Copy Markdown
Member Author

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

@savannahostrowski savannahostrowski 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.

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
@alexprengere

Copy link
Copy Markdown
Contributor

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?

I think this is the one #142035. The more colors applied, the more visible this will be 😉 .
IMO the clean solution would be to make some changes in textwrap.wrap, to handle graphemes and escape sequences (3.15 ships unicodedata.iter_graphemes). I would be happy to make those changes but I think this will be considered a new feature, thus should land in 3.16 now.

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.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.