[issue9334] argparse does not accept options taking arguments beginning with dash (regression from optparse)

paul j3 report at bugs.python.org
Thu Sep 15 18:48:34 EDT 2016


paul j3 added the comment:

Clint, the problem is the argparse uses different argument allocation method than optparse.

optparse gives the '--subscipt_args` Action all of the remaining strings, and says - 'consume what you want, and return the rest'.  So you consume up to (and including) the '--'.  Then optparse continues with the rest.

argparse performs the double pass described earlier, and allocates strings to each Action based on the larger context.  It gives as many as the Action's nargs requires, but tries in various ways to reserve strings for other Actions.  Individual Actions never see the big picture.

So the 'REMAINDER' action has to be last (with this '--' positional exception).  Your users will have to use the other flags Actions first.

One alternative comes to mind:

- omit the final positional
- use parse_known_args instead of parse_args

Then the 'extras' list will be something like:  ['--', '--verbose'], which you can handle in another parser.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9334>
_______________________________________


More information about the Python-bugs-list mailing list