Message307209
> 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.) |
|
Date |
User |
Action |
Args |
2017-11-29 05:54:48 | evaned | set | recipients:
+ evaned, cben, amcnabb, bethard, eric.smith, eric.araujo, r.david.murray, memeplex, gfxmonk, andersk, abacabadabacaba, gdb, nelhage, drm, davidben, martin.panter, paul.j3, skilletaudio, Christophe.Guillon, danielsh, spaceone, Clint Olsen |
2017-11-29 05:54:48 | evaned | set | messageid: <1511934888.07.0.213398074469.issue9334@psf.upfronthosting.co.za> |
2017-11-29 05:54:48 | evaned | link | issue9334 messages |
2017-11-29 05:54:47 | evaned | create | |
|