homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients bethard, elsdoerfer, eric.araujo, paul.j3, r.david.murray
Date 2014年07月07日.00:18:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1404692307.14.0.799271949275.issue9571@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014年07月07日 00:18:27paul.j3setrecipients: + paul.j3, bethard, eric.araujo, r.david.murray, elsdoerfer
2014年07月07日 00:18:27paul.j3setmessageid: <1404692307.14.0.799271949275.issue9571@psf.upfronthosting.co.za>
2014年07月07日 00:18:27paul.j3linkissue9571 messages
2014年07月07日 00:18:25paul.j3create

AltStyle によって変換されたページ (->オリジナル) /