10000 bpo-33109: argparse subparsers are once again not required by default by ned-deily · Pull Request #6919 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-33109: argparse subparsers are once again not required by default #6919

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 1 commit into from
May 24, 2018
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
2 changes: 1 addition & 1 deletion Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ Sub-commands
stored; by default ``None`` and no value is stored

* required_ - Whether or not a subcommand must be provided, by default
``True``.
``False``.

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

Expand Down
2 changes: 1 addition & 1 deletion Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ def __init__(self,
prog,
parser_class,
dest=SUPPRESS,
required=True,
required=False,
Copy link
Member

Choose a reason for hiding this comment

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

While we are here, please move required to the end of the list of parameters. It was inserted in the middle of non-keyword-only parameters.

Copy link
Contributor

Choose a reason for hiding this comment

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

This was discussed here

It makes no difference because add_subparsers does not take positional arguments (all arguments are keyword-only). The ordering here was chosen to be consistent with the rest of the classes in the module

Copy link
Member

Choose a reason for hiding this comment

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

Oh, sorry. You are right.

help=None,
metavar=None):

Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1932,7 +1932,9 @@ def test_required_subparsers_default(self):
parser = ErrorRaisingArgumentParser()
subparsers = parser.add_subparsers(dest='command')
subparsers.add_parser('run')
self._test_required_subparsers(parser)
# No error here
ret = parser.parse_args(())
self.assertIsNone(ret.command)

def test_optional_subparsers(self):
parser = ErrorRaisingArgumentParser()
Expand Down
2 changes: 2 additions & 0 deletions Misc/NEWS.d/3.7.0a2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ module now requires sqlite version at least 3.3.9.
argparse subparsers are now required by default. This matches behaviour in
Python 2. For optional subparsers, use the new parameter
``add_subparsers(required=False)``. Patch by Anthony Sottile.
(As of 3.7.0rc1, the default was changed to not required as had been the case
since Python 3.3.)

..

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
argparse subparsers are once again not required by default, reverting the
change in behavior introduced by bpo-26510 in 3.7.0a2.
0