Skip to content

Commit f19b4d7

Browse files
bpo-26510: Add versionchanged for required arg of add_subparsers (GH-16588)
The `required` argument to `argparse.add_subparsers` was added in GH-3027. This PR specifies the earliest version of Python where it is available. https://bugs.python.org/issue26510 Automerge-Triggered-By: @merwok (cherry picked from commit 9e71917) Co-authored-by: Adam J. Stewart <[email protected]>
1 parent ce3c913 commit f19b4d7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Doc/library/argparse.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ Sub-commands
15951595
stored; by default ``None`` and no value is stored
15961596

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

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

@@ -1751,6 +1751,9 @@ Sub-commands
17511751
>>> parser.parse_args(['2', 'frobble'])
17521752
Namespace(subparser_name='2', y='frobble')
17531753

1754+
.. versionchanged:: 3.7
1755+
New *required* keyword argument.
1756+
17541757

17551758
FileType objects
17561759
^^^^^^^^^^^^^^^^

Doc/whatsnew/3.7.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,6 +2401,10 @@ Changes in the Python API
24012401
instead of a :class:`bytes` instance.
24022402
(Contributed by Victor Stinner in :issue:`21071`.)
24032403

2404+
* :mod:`argparse` subparsers can now be made mandatory by passing ``required=True``
2405+
to :meth:`ArgumentParser.add_subparsers() <argparse.ArgumentParser.add_subparsers>`.
2406+
(Contributed by Anthony Sottile in :issue:`26510`.)
2407+
24042408
* :meth:`ast.literal_eval()` is now stricter. Addition and subtraction of
24052409
arbitrary numbers are no longer allowed.
24062410
(Contributed by Serhiy Storchaka in :issue:`31778`.)

0 commit comments

Comments
 (0)