Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
810fde1
gh-140281: Doc: Update free-threading how-to
Krishna-web-hub Oct 24, 2025
b9ca059
gh-140281: Doc: Update free-threading how-to
Krishna-web-hub Oct 24, 2025
bfbf864
Merge branch 'main' into doc-fix-140281
Krishna-web-hub Oct 24, 2025
16a1c46
Fix trailing whitespace
Krishna-web-hub Oct 24, 2025
639865d
Merge branch 'doc-fix-140281' of https://github.com/Krishna-web-hub/c…
Krishna-web-hub Oct 24, 2025
3f0aa48
doc fixing of the cpython fixes#84116
Krishna-web-hub Oct 25, 2025
343648b
Docs: Document help and aliases for argparse.add_parser() (gh-84116)
Krishna-web-hub Oct 25, 2025
4b07ba3
Docs: Document help and aliases for argparse.add_parser() (gh-84116)
Krishna-web-hub Oct 25, 2025
8bb4bae
Fix trailing whitespace
Krishna-web-hub Oct 25, 2025
3361447
Fix trailing whitespace
Krishna-web-hub Oct 25, 2025
100207d
Fix trailing whitespace
Krishna-web-hub Oct 25, 2025
0f27e63
Fix trailing whitespace
Krishna-web-hub Oct 25, 2025
7e6102a
Fix trailing whitespace
Krishna-web-hub Oct 25, 2025
a76954c
Fix trailing whitespace
Krishna-web-hub Oct 25, 2025
ac2b754
Fix trailing errors
Krishna-web-hub Oct 25, 2025
b08e8ed
Fix trailing errors and spaces
Krishna-web-hub Oct 25, 2025
fa1d877
Fix docutils formatting, NEWS ref, and trailing whitespace
Krishna-web-hub Oct 25, 2025
e955fb0
Docs: Update argparse.rst and add NEWS entry
Krishna-web-hub Oct 25, 2025
3d4cf26
Delete Doc/howto/free-threading-python.rst
Krishna-web-hub Oct 25, 2025
e3af10b
Delete Misc/NEWS.d/next/Documentation/2025-10-25-00-49-43.gh-issue-14…
Krishna-web-hub Oct 25, 2025
59a1ad9
adding the depreceated tag
Krishna-web-hub Dec 8, 2025
defd2c3
The error indexing was fixed
Krishna-web-hub Dec 8, 2025
cd445fc
Fix trailing whitespace
Krishna-web-hub Dec 8, 2025
2e270ef
Restore missing free-threading documentation
Krishna-web-hub Dec 8, 2025
3e87e19
fixing some minor error
Krishna-web-hub Dec 8, 2025
1867c71
fixing some minor error part 2
Krishna-web-hub Dec 8, 2025
ef450f6
fixing some minor error part 3
Krishna-web-hub Dec 8, 2025
4d27843
Fix NEWS entry format
Krishna-web-hub Dec 8, 2025
83ff9bf
Final cleanup of NEWS entry format 2
Krishna-web-hub Dec 8, 2025
77cc182
changes in the argparse.rst
Krishna-web-hub Dec 8, 2025
1a5c449
Remove unnecessary NEWS entry
Krishna-web-hub Dec 8, 2025
2dd07bb
Fixing the issue as requested
Krishna-web-hub Dec 11, 2025
850c986
Added the Changes done before.
Krishna-web-hub Dec 26, 2025
7f95d28
done the changes
Krishna-web-hub Dec 26, 2025
18cbbae
done the changes#1
Krishna-web-hub Dec 26, 2025
554a3ca
Apply suggestion from @picnixz
Krishna-web-hub Jan 1, 2026
312aa0f
Apply suggestion from @picnixz
Krishna-web-hub Jan 1, 2026
53031db
Done the changes
Krishna-web-hub Jan 2, 2026
6afe4d5
Done the new changes
Krishna-web-hub Jan 2, 2026
a10e6a5
The versionadded is rectified
Krishna-web-hub Jan 2, 2026
d551718
Merge branch 'main' into doc-fix-84116
Krishna-web-hub Jan 2, 2026
6f94eda
Update Doc/library/argparse.rst
Krishna-web-hub Jan 3, 2026
d0ccf81
Merge branch 'main' into doc-fix-84116
Krishna-web-hub Jan 5, 2026
99af040
Docs editing
Krishna-web-hub Jan 12, 2026
57d971d
Docs fixing whitespace
Krishna-web-hub Jan 12, 2026
2325383
Merge branch 'main' into doc-fix-84116
Krishna-web-hub Jan 12, 2026
f8c3bdd
Merge branch 'main' into doc-fix-84116
Krishna-web-hub Jan 12, 2026
2bea80e
Docs rectifiying
Krishna-web-hub Jan 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 62 additions & 45 deletions Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1700,20 +1700,20 @@ The Namespace object
Other utilities
---------------

Subcommands
Sub-commands
^^^^^^^^^^^^

.. method:: ArgumentParser.add_subparsers(*, [title], [description], [prog], \
[parser_class], [action], \
[dest], [required], \
[help], [metavar])

Many programs split up their functionality into a number of subcommands,
for example, the ``svn`` program can invoke subcommands like ``svn
Many programs split up their functionality into a number of sub-commands,
for example, the ``svn`` program can invoke sub-commands like ``svn
checkout``, ``svn update``, and ``svn commit``. Splitting up functionality
this way can be a particularly good idea when a program performs several
different functions which require different kinds of command-line arguments.
:class:`ArgumentParser` supports the creation of such subcommands with the
:class:`ArgumentParser` supports the creation of such sub-commands with the
:meth:`!add_subparsers` method. The :meth:`!add_subparsers` method is normally
called with no arguments and returns a special action object. This object
has a single method, :meth:`~_SubParsersAction.add_parser`, which takes a
Expand All @@ -1723,32 +1723,32 @@ Subcommands
Description of parameters:

* *title* - title for the sub-parser group in help output; by default
"subcommands" if description is provided, otherwise uses title for
positional arguments
"subcommands" if description is provided, otherwise uses title for
positional arguments
Comment on lines +1726 to +1727
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about those whitespaces. This should be aligned with the parameter itself as it's currently done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @picnixz ,
Here doing only t his indentation change may break the whole description of parameter indentation if you want i can fix the indentation issue of this like i can change every other parameter description in this format.

Copy link
Member

@picnixz picnixz Jan 12, 2026

Choose a reason for hiding this comment

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

Can you show us a screenshot please? because the current indentation is correct though?


* *description* - description for the sub-parser group in help output, by
default ``None``
default ``None``

* *prog* - usage information that will be displayed with subcommand help,
by default the name of the program and any positional arguments before the
subparser argument
by default the name of the program and any positional arguments before the
subparser argument

* *parser_class* - class which will be used to create sub-parser instances, by
default the class of the current parser (e.g. :class:`ArgumentParser`)
default the class of the current parser (e.g. :class:`ArgumentParser`)

* action_ - the basic type of action to be taken when this argument is
encountered at the command line
encountered at the command line

* dest_ - name of the attribute under which subcommand name will be
stored; by default ``None`` and no value is stored
stored; by default ``None`` and no value is stored

* required_ - Whether or not a subcommand must be provided, by default
``False`` (added in 3.7)
``False`` (added in 3.7)

* help_ - help for sub-parser group in help output, by default ``None``

* metavar_ - string presenting available subcommands in help; by default it
is ``None`` and presents subcommands in form {cmd1, cmd2, ..}
is ``None`` and presents subcommands in form {cmd1, cmd2, ..}

Some example usage::

Expand All @@ -1771,7 +1771,7 @@ Subcommands
>>> parser.parse_args(['--foo', 'b', '--baz', 'Z'])
Namespace(baz='Z', foo=True)

Note that the object returned by :meth:`parse_args` will only contain
Note that the object returned by :meth:`~ArgumentParser.parse_args` will only contain
attributes for the main parser and the subparser that was selected by the
command line (and not any other subparsers). So in the example above, when
the ``a`` command is specified, only the ``foo`` and ``bar`` attributes are
Expand Down Expand Up @@ -1814,7 +1814,7 @@ Subcommands
-h, --help show this help message and exit
--baz {X,Y,Z} baz help

The :meth:`add_subparsers` method also supports ``title`` and ``description``
The :meth:`~ArgumentParser.add_subparsers` method also supports ``title`` and ``description``
keyword arguments. When either is present, the subparser's commands will
appear in their own group in the help output. For example::

Expand All @@ -1835,34 +1835,8 @@ Subcommands

{foo,bar} additional help

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

One particularly effective way of handling subcommands is to combine the use
of the :meth:`add_subparsers` method with calls to :meth:`set_defaults` so
of the :meth:`~ArgumentParser.add_subparsers` method with calls to :meth:`~ArgumentParser.set_defaults` so
that each subparser knows which Python function it should execute. For
example::

Expand Down Expand Up @@ -1898,12 +1872,12 @@ Subcommands
>>> args.func(args)
((XYZYX))

This way, you can let :meth:`parse_args` do the job of calling the
This way, you can let :meth:`~ArgumentParser.parse_args` do the job of calling the
appropriate function after argument parsing is complete. Associating
functions with actions like this is typically the easiest way to handle the
different actions for each of your subparsers. However, if it is necessary
to check the name of the subparser that was invoked, the ``dest`` keyword
argument to the :meth:`add_subparsers` call will work::
argument to the :meth:`~ArgumentParser.add_subparsers` call will work::

>>> parser = argparse.ArgumentParser()
>>> subparsers = parser.add_subparsers(dest='subparser_name')
Expand All @@ -1922,6 +1896,49 @@ Subcommands
the main parser.


.. method:: _SubParsersAction.add_parser(name, *, help=None, aliases=None,
deprecated=False, **kwargs)

Creates and returns a new :class:`!ArgumentParser` object for the
subcommand *name*.

The *name* argument is the name of the sub-command.

The *help* argument provides a short description for this sub-command.
If provided, it will be listed next to the command in the main parser’s
help message (for example, ``PROG --help``).

The *aliases* argument allows providing alternative names for this
sub-command.

For example::

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

The *deprecated* argument, if ``True``, marks the sub-command as
deprecated and will issue a warning when used.

For example::

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

.. versionadded:: 3.13
Added the *deprecated* parameter.


All other keyword arguments are passed directly to the
:class:`!ArgumentParser` constructor.

FileType objects
^^^^^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Document ``help`` and ``aliases`` parameters for
``argparse._SubParsersAction.add_parser`` in the :mod:`argparse`
documentation.
Loading