Skip to content

gh-58247: clarify metavar behaviour in ArgumentParser.add_subparsers - #148671

Open
SofieTorch wants to merge 2 commits into
python:mainfrom
SofieTorch:gh-58247-fix-subparsers-metavar-docs
Open

gh-58247: clarify metavar behaviour in ArgumentParser.add_subparsers#148671
SofieTorch wants to merge 2 commits into
python:mainfrom
SofieTorch:gh-58247-fix-subparsers-metavar-docs

Conversation

@SofieTorch

@SofieTorchSofieTorch commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Documents how metavar arg affects the --help output in subparsers.

Related to issue #58247


📚 Documentation preview 📚: https://cpython-previews--148671.org.readthedocs.build/

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

Thanks Sofie!

@bedevere-app

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

is ``None`` and presents subcommands in form {cmd1, cmd2, ..}
is ``None`` and presents subcommands in form {cmd1, cmd2, ..} in the usage line
and next to the subparsers group heading. It does not change how the
individual subcommands are listed below that heading

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'd suggest using the same format as the description for dest. Maybe something like the following will keep it more concise (argparse docs are already quite long 😅 ):

* metavar_ - placeholder shown in the usage line and in the help entry for the subparsers argument
in place of {cmd1, cmd2, ..}; by default ``None``

This wasn't something you changed but technically speaking, metavar actually replaces the list of subcommands, it doesn't present it.

@savannahostrowskisavannahostrowski moved this from Todo to In Progress in Docs PRsApr 20, 2026
@savannahostrowskisavannahostrowski linked an issue Jun 5, 2026 that may be closed by this pull request
@savannahostrowski

Copy link
Copy Markdown
Member

Hey @SofieTorch, still up for finishing this one? Happy to chat more too!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting changesdocsDocumentation in the Doc dirskip news

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Add "metavar" argument to add_subparsers() in argparse

2 participants

@SofieTorch@savannahostrowski