diff options
author | Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com> | 2019-05-21 17:47:42 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-05-21 17:47:42 (GMT) |
commit | aa32a7e1116f7aaaef9fec453db910e90ab7b101 (patch) | |
tree | 2e361b8ada3bdcaac42a8aa0e237baaf814d66c9 /Lib/argparse.py | |
parent | d5c120f7eb6f2a9cdab282a5d588afed307a23df (diff) | |
download | cpython-aa32a7e1116f7aaaef9fec453db910e90ab7b101.zip cpython-aa32a7e1116f7aaaef9fec453db910e90ab7b101.tar.gz cpython-aa32a7e1116f7aaaef9fec453db910e90ab7b101.tar.bz2 |
bpo-23378: Add an extend action to argparse (GH-13305)
Add an extend action to argparse
https://bugs.python.org/issue23378
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r-- | Lib/argparse.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py index 798766f..ef888f0 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -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() |