Skip to content

Conversation

@Krishna-web-hub
Copy link
Contributor

@Krishna-web-hub Krishna-web-hub commented Oct 25, 2025

gh-84116: Doc: update the argparse documentation to clearly define the help and aliases parameters for add_parser() and added the required news file for this change.

Doc/library/argparse.rst

Replaced the vague, single-sentence description of _SubParsersAction.add_parser with a formal .. method:: directive.

This new directive explicitly lists help and aliases as parameters, along with descriptions of what they do.

Removed the old, redundant paragraphs about help (which was in parentheses) and aliases (which was a "Furthermore..." note) from later in the document. This centralizes all the information in one logical place.

Misc/NEWS.d/next/Library/...

Added the required "blurb" file to log this documentation fix.


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

@StanFromIreland StanFromIreland changed the title Doc fix 84116Docs: Document help and aliases for argparse.add_parser() (gh-84116) #84116 gh-84116: Docs: Document help and aliases for argparse.add_parser() Oct 25, 2025
Copy link
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seem to be two different things mixed in this PR, please split it.

@Krishna-web-hub
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-app
Copy link

bedevere-app bot commented Dec 9, 2025

Thanks for making the requested changes!

@picnixz, @savannahostrowski: please review the changes made to this pull request.

Copy link
Member

@savannahostrowski savannahostrowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates. A few comments:

  • Can we make add_parser a top-level method directive rather than nesting it under add_subparsers? Right now it's a bit muddled. I think placing it around line 1807 (after the add_subparsers examples) would work well.
  • Related to the last point, the existing sections about add_parser aliases and deprecated further down in the docs are now redundant. We can remove those paragraphs and incorporate the content/examples into the new add_parser documentation.

@bedevere-app
Copy link

bedevere-app bot commented Dec 9, 2025

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.

And if you don't make the requested changes, you will be put in the comfy chair!

@Krishna-web-hub
Copy link
Contributor Author

Krishna-web-hub commented Dec 11, 2025

Hi @savannahostrowski ,@picnixz I have made the requested changes; please review again.

@bedevere-app
Copy link

bedevere-app bot commented Dec 11, 2025

Thanks for making the requested changes!

@savannahostrowski, @picnixz: please review the changes made to this pull request.

@Krishna-web-hub
Copy link
Contributor Author

Hi @savannahostrowski , @picnixz i have done all the changes according to your message been waiting for any further changes.

@Krishna-web-hub
Copy link
Contributor Author

Apologies for the confusion
@savannahostrowski @picnixz.
​I realized that my local commits were not successfully pushed when I posted my last message. I have just pushed the correct changes now, and the checks have passed. The PR is ready for review again.

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still unrelated changes. Please avoid asking for a review if there is still things to change and address.

---------------

Sub-commands
Subcommands
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can revert this change. Changing it would change the generated indices and thus break existing URLs, which is not always a good idea.

subcommand *name*.

The *name* argument is the name of the subcommand.
The *help* argument provides a short description for this subcommand. If provided, it will be listed next to the command in the main parser's help message (e.g., ``PROG --help``).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap lines under 80 characters.

The *aliases* argument allows to provide a sequence of strings that can be used as alternative names for this subcommand (e.g., ``aliases=['r']`` for a ``'run'`` command).

The *deprecated* argument, if :const:`True`, marks the subcommand as deprecated, which typically issues a warning when used.
All other keyword arguments are passed directly to the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
All other keyword arguments are passed directly to the
All other keyword arguments are passed directly to the

The *deprecated* argument, if :const:`True`, marks the subcommand as deprecated, which typically issues a warning when used.
All other keyword arguments are passed directly to the
:class:`!ArgumentParser` constructor.
This returned :class:`!ArgumentParser` object can be modified as usual.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This returned :class:`!ArgumentParser` object can be modified as usual.

Description of parameters:

* *title* - title for the sub-parser group in help output; by default
* *title* - title for the subparser group in help output; by default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert those unrelated changes. Or more generally, why was this changed?

*aliases* argument,
which allows multiple strings to refer to the same subparser. This example,
like ``svn``, aliases ``co`` as a shorthand for ``checkout``::
.. method:: _SubParsersAction.add_parser(name, *, help=None, aliases=None, deprecated=False, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have a duplicated entry here?

>>> parser.parse_args(['fly']) # doctest: +SKIP
chicken.py: warning: command 'fly' is deprecated
Namespace()
The help argument provides a short description for this subcommand.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge the documentation but chose whether to place it here or elsewhere. It doesn't make sense to have duplicated text. As for the examples, either put them below the documented method or in a dedicated section.

Sometimes it's desirable to use a custom string in error messages to provide
more user-friendly output. In these cases, :meth:`!register` can be used to
register custom actions or types with a parser and allow you to reference the
register custom actions or types with a parser anto reference the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed?

@bedevere-app
Copy link

bedevere-app bot commented Dec 28, 2025

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.

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

Labels

awaiting changes docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

5 participants