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

gh-142389: Add support for backtick colorisation in argparse help text by hugovk · Pull Request #149375 · python/cpython · GitHub

/ cpython Public

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

Merged
hugovk merged 8 commits into
python: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 into
python:mainfrom
hugovk:3.15-argparse-help-backticks

Conversation

hugovk commented May 4, 2026
edited by bedevere-app Bot
Loading

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:

Will add to other stdlib CLIs in a followup.

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

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

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

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:

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 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 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 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 Bot requested a review from savannahostrowski May 4, 2026 21:28

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.

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

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

With NO_COLOR:

Whereas with color:

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

Sweeeeet! Thank Hugo!

hugovk enabled auto-merge (squash) May 4, 2026 22:43
hugovk merged commit ffe050a into python:main May 4, 2026
55 of 56 checks passed
hugovk deleted the 3.15-argparse-help-backticks branch May 4, 2026 22:58

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.

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

stdlib Standard Library Python modules in the Lib/ directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL