mirror of
https://github.com/python/cpython.git
synced 2025-08-24 02:35:59 +00:00
bpo-23378: Add an extend action to argparse (GH-13305)
Add an extend action to argparse https://bugs.python.org/issue23378
This commit is contained in:
parent
d5c120f7eb
commit
aa32a7e111
4 changed files with 26 additions and 0 deletions
|
@ -1154,6 +1154,12 @@ class _SubParsersAction(Action):
|
|||
vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, [])
|
||||
getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings)
|
||||
|
||||
class _ExtendAction(_AppendAction):
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
items = getattr(namespace, self.dest, None)
|
||||
items = _copy_items(items)
|
||||
items.extend(values)
|
||||
setattr(namespace, self.dest, items)
|
||||
|
||||
# ==============
|
||||
# Type classes
|
||||
|
@ -1262,6 +1268,7 @@ class _ActionsContainer(object):
|
|||
self.register('action', 'help', _HelpAction)
|
||||
self.register('action', 'version', _VersionAction)
|
||||
self.register('action', 'parsers', _SubParsersAction)
|
||||
self.register('action', 'extend', _ExtendAction)
|
||||
|
||||
# raise an exception if the conflict handler is invalid
|
||||
self._get_handler()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue