Skip to content

bpo-26510: Add versionchanged for required arg of add_subparsers #16588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ Sub-commands
stored; by default ``None`` and no value is stored

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

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

Expand Down Expand Up @@ -1792,6 +1792,9 @@ Sub-commands
>>> parser.parse_args(['2', 'frobble'])
Namespace(subparser_name='2', y='frobble')

.. versionchanged:: 3.7
New *required* keyword argument.


FileType objects
^^^^^^^^^^^^^^^^
Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,10 @@ Changes in the Python API
instead of a :class:`bytes` instance.
(Contributed by Victor Stinner in :issue:`21071`.)

* :mod:`argparse` subparsers can now be made mandatory by passing ``required=True``
to :meth:`ArgumentParser.add_subparsers() <argparse.ArgumentParser.add_subparsers>`.
Copy link
Member

@merwok merwok Oct 7, 2019

Choose a reason for hiding this comment

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

Small thing I didn’t notice before merge: in func/meth/etc roles, we don’t include the parentheses. Sphinx has a setting to add them or not automatically to all roles (I think it’s smart enough to not add them if already present, but not 100% sure, will check when the docs rebuild is published).

(I personnally don’t like to have them, especially given Python’s clear difference of referencing a function vs. calling it, but many programmers are used to writing things like the whatever() function probably to make it less ambiguous in plain text contexts like email, so Python’s doc is set up to have them 🙂)

I didn’t pay attention to the fact that the section here (Changes in the Python API) was part of Porting to Python 3.7 (we really need docs previews for PRs!), which made sense in the original PR (changed argparse behaviour) but less so now. I think it would have been better in Improved Modulesargparse https://docs.python.org/3.9/whatsnew/3.7.html#argparse

(Contributed by Anthony Sottile in :issue:`26510`.)

* :meth:`ast.literal_eval()` is now stricter. Addition and subtraction of
arbitrary numbers are no longer allowed.
(Contributed by Serhiy Storchaka in :issue:`31778`.)
Expand Down