Message222427
In elsdoerfer's example, the '--' effectively ends the argument list for '--ignore'. '--' are not allowed in the arguments of an optional (see the end of '_get_nargs_pattern()').
Rather the problem is at the start of _get_values()
if action.nargs not in [PARSER, REMAINDER]:
arg_strings = [s for s in arg_strings if s != '--']
'--' is not stripped out of the 'parser' input, hence the error message:
error: invalid choice: '--'
You can see this by replacing the subparsers with an argument with 'nargs=PARSER'. The argument will get `['--','COMMAND',...]`.
http://bugs.python.org/issue13922 tries to rework how '--' are handled. Ideally only the current '--' should be removed, leaving the rest to be handled by the subparser (or whoever else gets the strings).
Looks like the 13922 fix needs another fix, one that removes '--' if it is the 1st string for a REMAINDER or PARSER argument.
With that fix:
./script.py --ignore one two -- COMMAND arg1 arg2
should work, assigning ['one','two'] to 'ignore', and ['arg1','arg2'] to 'COMMAND's positional.
(I've tested this in a development version with many other changes. I'll try to write a simpler patch.)
----------------
If a 'end of a list' flag is still needed (as between 2 * positionals), a 'counter' or 'store_true' optional could be used. Or a new action class that doesn't write anything to the namespace could be written. |
|
Date |
User |
Action |
Args |
2014-07-07 00:18:27 | paul.j3 | set | recipients:
+ paul.j3, bethard, eric.araujo, r.david.murray, elsdoerfer |
2014-07-07 00:18:27 | paul.j3 | set | messageid: <1404692307.14.0.799271949275.issue9571@psf.upfronthosting.co.za> |
2014-07-07 00:18:27 | paul.j3 | link | issue9571 messages |
2014-07-07 00:18:25 | paul.j3 | create | |
|