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 Christophe.Guillon, Clint Olsen, abacabadabacaba, amcnabb, andersk, bethard, cben, danielsh, davidben, drm, eric.araujo, eric.smith, evaned, gdb, gfxmonk, martin.panter, memeplex, nelhage, paul.j3, r.david.murray, rhettinger, skilletaudio, spaceone
Date 2017-12-07.01:04:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1512608666.23.0.213398074469.issue9334@psf.upfronthosting.co.za>
In-reply-to
Content
In the recently pushed, https://bugs.python.org/issue14191, "argparse doesn't allow optionals within positionals"

we added new parsing functionality by defining a new parser method:

parse_intermixed_args

It added functionality without requiring a new parameter for the parser (no point in confusing users with parameters they don't need or understand).  It was also a good fit because it worked on top of the default parser, fidling with the nargs to parse positionals and options in different runs. 

I would like to see something similar for this problem.  Define a

parser.parse_opt_args() method 

that tries, as much as possible to follow the optparse strategy.  As I commented previously, the difference in behavior starts at the top.  

argparse distinguishes between flag (optiona) and argument strings based on the dash(es), and then allocates strings to the Actions based on that pattern and nargs.  It also alternates between handling positionals and optionals.

optparse passes all the remaining strings to an Action, lets it consume what it wants, and resumes parsing with the remainder.  It does not handle positionals; those are just accumulated in an 'extras' list (sort of like parse_known_args without any defined positionals).

An unknown in this approach is whether the argparse.Action class(es) can be adapted to this 'consume what you want' strategy.  It would be nice if such an alternative parser could be written that doesn't require any changes to the Action.  We don't have to go so far as to allow custom Action classes that imitate optparse Options.

But I haven't thought about this problem since 2013.  I don't sense either, from other bug/issues, or Stackoverflow questions, that this is a pressing need.
History
Date User Action Args
2017-12-07 01:04:26paul.j3setrecipients: + paul.j3, rhettinger, cben, amcnabb, bethard, eric.smith, eric.araujo, r.david.murray, memeplex, gfxmonk, evaned, andersk, abacabadabacaba, gdb, nelhage, drm, davidben, martin.panter, skilletaudio, Christophe.Guillon, danielsh, spaceone, Clint Olsen
2017-12-07 01:04:26paul.j3setmessageid: <1512608666.23.0.213398074469.issue9334@psf.upfronthosting.co.za>
2017-12-07 01:04:26paul.j3linkissue9334 messages
2017-12-07 01:04:23paul.j3create