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 Kotan, bethard, catherine, elsdoerfer, eric.araujo, paul.j3, wrobell
Date 2013-05-17.17:02:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This patch implements, I think, the ideas bethard proposed.  It is test patch, not intended for production.

Most of work is in ArgumentParser._get_alt_length() which
- generates a pattern along the lines bethard proposed
- generates a string like arg_strings_pattern, but with optionals strings ('-x') instead of 'O'.
- runs a match
- from groups like '-xAAA', creates dict entries like: 
    alt_opt_length['x'] = 3

Later, in consume_optionals(), this alternative count replaces arg_count if it is lower.  The next consume_positionals() then takes care of consuming the unconsumed arguments.

If _get_alt_length() has any problems, it logs an error, and returns an otherwise empty dict.  So it 'fails' quietly without affecting regular parsing.

Reasons for failing include (for now) the use of subparsers, optionals with explicit args, and special prefix_chars.  With exclusions like this, runs without errors or failures.

Since this is still a testing vehicle, it writes an issue9338.log file with debugging entries.

This version works, but is both not sufficiently general and too general.  As bethard notes, the testing pattern could get very large if there are many optionals.  Ideally the pattern will allow the optionals in any order and combination between positionals.  The ambiguities that I discussed in the previous 2 posts disappear if the patching pattern is sufficiently general.

But I also suspect it is too general.  It does not need to match every case, just those where an optional is consuming arguments that should go to a positional.  But if we come up with something more specific, this could still be a useful testing tool.
Date User Action Args
2013-05-17 17:02:41paul.j3setrecipients: + paul.j3, bethard, wrobell, eric.araujo, catherine, elsdoerfer, Kotan
2013-05-17 17:02:40paul.j3setmessageid: <>
2013-05-17 17:02:40paul.j3linkissue9338 messages
2013-05-17 17:02:40paul.j3create