Evan Driscoll <[email protected]> added the comment:
> I also think that nargs=## could maybe be special-cased to just ignore
> the A/O designation completely and only check there are enough, but I
> haven't tried this out. Does this seem like a viable approach? Would a
> patch that does that, subject to some flag, be of interest?
I can't leave well enough alone, so, with the following additional patch:
- def _match_argument(self, action, arg_strings_pattern):
+ def _match_argument(self, action, arg_strings_pattern, arg_strings,
start_index):
+ import numbers
+ nargs = action.nargs if action.nargs is not None else 1
+ if isinstance(nargs, numbers.Number) and len(arg_strings_pattern) >=
nargs:
+ return nargs
+
# match the pattern for this action to the arg strings
nargs_pattern = self._get_nargs_pattern(action)
match = _re.match(nargs_pattern, arg_strings_pattern)
...
Then I get this:
>>> import argparse
>>> parser = argparse.ArgumentParser(prog='a2x')
>>> parser.add_argument('--asciidoc-opts',
... action='store', dest='asciidoc_opts', default='',
... metavar='ASCIIDOC_OPTS', help='asciidoc options')
>>> parser.parse_args(['--asciidoc-opts', '--safe'])
Namespace(asciidoc_opts='--safe')
Comments on this approach?
(Again, I haven't run tests, it'd need to be controlled by a flag per your
desire to not change existing behavior, etc.)
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue9334>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com