← 返回首页
gh-99735: Handle no arguments when using sub-commands in argparse by ppaez · Pull Request #99736 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

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

Provide feedback

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

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

gh-99735: Handle no arguments when using sub-commands in argparse#99736

Closed
ppaez wants to merge 3 commits into
python:mainfrom
ppaez:argparse-documentation
Closed

gh-99735: Handle no arguments when using sub-commands in argparse#99736
ppaez wants to merge 3 commits into
python:mainfrom
ppaez:argparse-documentation

Conversation

ppaez commented Nov 23, 2022
edited
Loading

Copy link
Copy Markdown
Contributor

This provides a fix to improve the example in the documentation.

ghost commented Nov 23, 2022
edited by ghost
Loading

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

ppaez changed the title gh-58247: Handle no arguments when using sub-commands in argparse gh-99735: Handle no arguments when using sub-commands in argparse Nov 23, 2022
Comment thread Doc/library/argparse.rst
Comment on lines +1855 to +1858
One particularly effective way of handling sub-commands is to
combine the use of the :meth:`add_subparsers` method with calls to
:meth:`set_defaults` so that each subparser knows which Python
function it should execute. The :meth:`set_defaults` method of the

Copy link
Copy Markdown
Contributor

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

I'd recommend keeping the original structure so just the new changes can be more easily reviewed.

Suggested change
One particularly effective way of handling sub-commands is to
combine the use of the :meth:`add_subparsers` method with calls to
:meth:`set_defaults` so that each subparser knows which Python
function it should execute. The :meth:`set_defaults` method of the
One particularly effective way of handling sub-commands is to combine the use
of the :meth:`add_subparsers` method with calls to :meth:`set_defaults` so
that each subparser knows which Python function it should execute.
The :meth:`set_defaults` method of the

Comment thread Doc/library/argparse.rst
combine the use of the :meth:`add_subparsers` method with calls to
:meth:`set_defaults` so that each subparser knows which Python
function it should execute. The :meth:`set_defaults` method of the
main parser is called to handle the case when no subcommand is

Copy link
Copy Markdown
Contributor

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

tiny nit, since 'sub-command' was used above in the same paragraph

Suggested change
main parser is called to handle the case when no subcommand is
main parser is called to handle the case when no sub-command is

Copy link
Copy Markdown
Contributor

Thanks! Closing in favour of #100927

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

awaiting review docs Documentation in the Doc dir skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Footer

© 2026 GitHub, Inc.