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 paul.j3, tellendil
Date 2015-05-12.22:12:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1431468724.07.0.91123441767.issue24166@psf.upfronthosting.co.za>
In-reply-to
Content
Look at http://bugs.python.org/issue9338
argparse optionals with nargs='?', '*' or '+' can't be followed by positionals

That has a proposed patch that wraps the main argument consumption loop in another loop.

The current loop alternatively consumes optionals and positionals until the argv list is done.  The `consume_loop` method in that patch tries various allocations of argv strings between optionals and positionals.  It performs 'dry' runs until it finds something that consumes most of the strings, and then does the actual parsing with changes to the namespace.

The idea might be adapted to work with subparsers, paying attention, as you do, to the 'extras' from parse_known_args.  But it might be hard to reliably perform a 'dry' run when subparsers are involved.

I suspect that any change along this line will be too complex to ever be the default behavior.  The chances of messing with backward compatibility are just too great.  It might pass as an alternative parsing call.
History
Date User Action Args
2015-05-12 22:12:04paul.j3setrecipients: + paul.j3, tellendil
2015-05-12 22:12:04paul.j3setmessageid: <1431468724.07.0.91123441767.issue24166@psf.upfronthosting.co.za>
2015-05-12 22:12:04paul.j3linkissue24166 messages
2015-05-12 22:12:04paul.j3create