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-99735: Handle no arguments when using sub-commands in argparse by ppaez · Pull Request #99736 · python/cpython

Conversation

@ppaez

@ppaez ppaez commented Nov 23, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

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

  • Issue: Handle no arguments when using sub-commands in argparse #99735

Sorry, something went wrong.

Uh oh!

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

All reactions
ppaez added 3 commits November 23, 2022 15:03
@ppaez
Show the main help if no arguments and using sub-commands
484f611
@ppaez
Add this case to the example
268de90
@ppaez
Add explanation in the documentation
a2687c6
@bedevere-bot bedevere-bot mentioned this pull request Nov 23, 2022
Add "metavar" argument to add_subparsers() in argparse #58247
Closed
@bedevere-bot bedevere-bot added awaiting review docs Documentation in the Doc dir skip news labels Nov 23, 2022
@ghost

ghost commented Nov 23, 2022 •
edited by ghost
Loading

Uh oh!

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

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

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

@ppaez 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
@bedevere-bot bedevere-bot mentioned this pull request Nov 23, 2022
Handle no arguments when using sub-commands in argparse #99735
Closed
slateny
slateny reviewed Dec 20, 2022
View reviewed changes
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

@slateny slateny Dec 20, 2022

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

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

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

@slateny slateny Dec 20, 2022

Copy link
Copy Markdown
Contributor

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.

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

Sorry, something went wrong.

Uh oh!

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

All reactions
@hauntsaninja

hauntsaninja commented Feb 19, 2023

Copy link
Copy Markdown
Contributor

Thanks! Closing in favour of #100927

All reactions

Sorry, something went wrong.

Uh oh!

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

@hauntsaninja hauntsaninja closed this Feb 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@slateny slateny slateny left review comments

Uh oh!

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

Assignees

No one assigned

Labels

awaiting review docs Documentation in the Doc dir skip news

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

@ppaez @hauntsaninja @slateny @bedevere-bot
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.