Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(39435)

Unified Diff: Lib/argparse.py

Issue 9253: argparse: optional subparsers
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Doc/library/argparse.rst ('k') | Lib/test/test_argparse.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/argparse.py Tue Apr 09 17:23:27 2013 +0200
+++ b/Lib/argparse.py Fri Apr 12 22:49:30 2013 -0700
@@ -696,6 +696,8 @@
return argument.metavar
elif argument.dest not in (None, SUPPRESS):
return argument.dest
+ elif hasattr(argument, 'name'):
+ return argument.name()
else:
return None
@@ -1057,6 +1059,7 @@
prog,
parser_class,
dest=SUPPRESS,
+ required=True,
help=None,
metavar=None):
@@ -1070,6 +1073,7 @@
dest=dest,
nargs=PARSER,
choices=self._name_parser_map,
+ required=required,
help=help,
metavar=metavar)
@@ -1124,6 +1128,9 @@
vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, [])
getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings)
+ def name(self):
+ # custom name for _get_action_name()
+ return "{%s}"%','.join(self._name_parser_map)
# ==============
# Type classes
@@ -1977,6 +1984,7 @@
self._get_value(action, action.default))
if required_actions:
+ required_actions = ['%s'%name for name in required_actions]
self.error(_('the following arguments are required: %s') %
', '.join(required_actions))
@@ -1992,6 +2000,7 @@
names = [_get_action_name(action)
for action in group._group_actions
if action.help is not SUPPRESS]
+ names = ['%s'%name for name in names]
msg = _('one of the arguments %s is required')
self.error(msg % ' '.join(names))
« no previous file with comments | « Doc/library/argparse.rst ('k') | Lib/test/test_argparse.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+