Skip to content

Conversation

@Krishna-web-hub
Copy link

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

Copy link
Member

Choose a reason for hiding this comment

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

Why are you deleting this?!

Copy link
Author

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

Choose a reason for hiding this comment

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

Hello @StanFromIreland ,
Because i by mistakenly added the other branch commit in this branch.
please let me raise a new pr for it.I am very sorry for this mistake

@StanFromIreland StanFromIreland marked this pull request as draft October 25, 2025 14:01
dreadstache

This comment was marked as spam.

dreadstache

This comment was marked as spam.

dreadstache

This comment was marked as spam.

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 kicking this off! My main comment on this is where to place this content, and some additional restructuring to reconcile duplicative content!

We'll also need to add back the doc on free threading (no worries there, it happens to everyone from time to time 😅 !)

Comment on lines 1809 to 1834
Furthermore, :meth:`~_SubParsersAction.add_parser` supports an additional
*aliases* argument,
which allows multiple strings to refer to the same subparser. This example,
like ``svn``, aliases ``co`` as a shorthand for ``checkout``::

>>> parser = argparse.ArgumentParser()
>>> subparsers = parser.add_subparsers()
>>> checkout = subparsers.add_parser('checkout', aliases=['co'])
>>> checkout.add_argument('foo')
>>> parser.parse_args(['co', 'bar'])
Namespace(foo='bar')

:meth:`~_SubParsersAction.add_parser` supports also an additional
*deprecated* argument, which allows to deprecate the subparser.

>>> import argparse
>>> parser = argparse.ArgumentParser(prog='chicken.py')
>>> subparsers = parser.add_subparsers()
>>> run = subparsers.add_parser('run')
>>> fly = subparsers.add_parser('fly', deprecated=True)
>>> parser.parse_args(['fly']) # doctest: +SKIP
chicken.py: warning: command 'fly' is deprecated
Namespace()

.. versionadded:: 3.13

Copy link
Member

Choose a reason for hiding this comment

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

I would actually recommend adding the formal documentation for the ~_SubParsersAction.add_parser method just above this block. We can remove this redundant section about aliases and incorporate deprecated as well.

I'm thinking something like:

.. method:: _SubParsersAction.add_parser(name, *, help=None, aliases=None, deprecated=False, **kwargs)
<rest of method docs>

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

The following example shows how to use *aliases* to create a shorthand
for a subcommand, like ``svn`` uses ``co`` for ``checkout``::
<examples>

@bedevere-app
Copy link

bedevere-app bot commented Oct 27, 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

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants