Skip to content

Commit 50b8d57

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 b40442b commit 50b8d57

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
@@ -1583,7 +1583,7 @@ Sub-commands
15831583
stored; by default ``None`` and no value is stored
15841584

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

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

@@ -1739,6 +1739,9 @@ Sub-commands
17391739
>>> parser.parse_args(['2', 'frobble'])
17401740
Namespace(subparser_name='2', y='frobble')
17411741

1742+
.. versionchanged:: 3.7
1743+
New *required* keyword argument.
1744+
17421745

17431746
FileType objects
17441747
^^^^^^^^^^^^^^^^

Doc/whatsnew/3.7.rst

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

2417+
* :mod:`argparse` subparsers can now be made mandatory by passing ``required=True``
2418+
to :meth:`ArgumentParser.add_subparsers() <argparse.ArgumentParser.add_subparsers>`.
2419+
(Contributed by Anthony Sottile in :issue:`26510`.)
2420+
24172421
* :meth:`ast.literal_eval()` is now stricter. Addition and subtraction of
24182422
arbitrary numbers are no longer allowed.
24192423
(Contributed by Serhiy Storchaka in :issue:`31778`.)

0 commit comments

Comments
 (0)