8000 bpo-26510: Allow argparse add_subparsers to take `required` kwarg. by asottile · Pull Request #3027 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-26510: Allow argparse add_subparsers to take required kwarg. #3027

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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Minor tweaks
  • Loading branch information
merwok authored and asottile committed Sep 20, 2017
commit 28bfe647ab91a617f8c032fcc74891faacfa0650
4 changes: 3 additions & 1 deletion Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,8 @@ def _test_required_subparsers(self, parser):
# Should parse the sub command
ret = parser.parse_args(['run'])
self.assertEqual(ret.command, 'run')
# Should error when missing the command

# Error when the command is missing
self.assertArgumentParserError(parser.parse_args, ())

def test_required_subparsers_via_attribute(self):
Expand All @@ -1937,6 +1938,7 @@ def test_optional_subparsers(self):
parser = ErrorRaisingArgumentParser()
subparsers = parser.add_subparsers(dest='command', required=False)
subparsers.add_parser('run')
# No error here
ret = parser.parse_args(())
self.assertIsNone(ret.command)

Expand Down
0