GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-142389: Add support for backtick colorisation in argparse help text by hugovk · Pull Request #149375 · python/cpython

Conversation

@hugovk

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

Uh oh!

There was an error while loading. Please reload this page.

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.

  • Issue: Add support for colorizing code examples in argparse description/epilog #142389

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
hugovk added 2 commits May 4, 2026 19:57
@hugovk
Add support for backtick colorisation in argparse help text
c51f27c
@hugovk
Backticks in regrtest
d8f6526
@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
@bedevere-app bedevere-app Bot added the awaiting core review label May 4, 2026
@bedevere-app bedevere-app Bot mentioned this pull request May 4, 2026
Add support for colorizing code examples in argparse description/epilog #142389
Closed
@read-the-docs-community

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

Uh oh!

There was an error while loading. Please reload this page.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

savannahostrowski
savannahostrowski requested changes May 4, 2026
View reviewed changes

@savannahostrowski savannahostrowski left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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?)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/argparse.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting changes and removed awaiting core review labels May 4, 2026
@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hugovk and others added 4 commits May 5, 2026 00:03
@hugovk @savannahostrowski
Update regex to match double backticks
254ef3c
Co-authored-by: Savannah Ostrowski <[email protected]>
@hugovk
Fix bad GitHub UI suggestion
601a82b
@hugovk
Revert "Backticks in regrtest"
6da5763
This reverts commit d8f6526.
@hugovk
Update docs, docstring and tests
138caa2
@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.

savannahostrowski reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting change review and removed awaiting changes labels May 4, 2026
@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app
bedevere-app Bot requested a review from savannahostrowski May 4, 2026 21:28
StanFromIreland
StanFromIreland reviewed May 4, 2026
View reviewed changes

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hugovk hugovk mentioned this pull request May 4, 2026
gh-142389: Add backticks to stdlib argparse help to display in colour #149384
Merged
@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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

savannahostrowski reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

savannahostrowski
savannahostrowski reviewed May 4, 2026
View reviewed changes
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_argparse.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

hugovk added 2 commits May 5, 2026 01:30
@hugovk
Split What's New
67f92b7
@hugovk
Add extra regression test for double backticks
634cfe6
savannahostrowski
savannahostrowski approved these changes May 4, 2026
View reviewed changes

@savannahostrowski savannahostrowski left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hugovk reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@bedevere-app bedevere-app Bot removed the awaiting change review label May 4, 2026
@bedevere-app bedevere-app Bot added the awaiting merge label May 4, 2026
@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

Uh oh!

There was an error while loading. Please reload this page.

@hugovk
hugovk deleted the 3.15-argparse-help-backticks branch May 4, 2026 22:58
@bedevere-app bedevere-app Bot removed the awaiting merge label May 4, 2026
@alexprengere

alexprengere commented May 5, 2026

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DavidCEllis DavidCEllis mentioned this pull request May 6, 2026
gh-148823: Avoid importing _colorize when creating an ArgumentParser #148827
Merged
This was referenced Oct 17, 2026
Python 3.15: AttributeError from argparse on every tmuxp command tmux-python/tmuxp#1094
Closed
cihai fails on Python 3.15: _theme clashes with argparse cihai/cihai-cli#359
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@StanFromIreland StanFromIreland StanFromIreland left review comments
@savannahostrowski savannahostrowski savannahostrowski approved these changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

stdlib Standard Library Python modules in the Lib/ directory

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@hugovk @alexprengere @savannahostrowski @StanFromIreland
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.