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-23.16:20:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Here's another approach to the problem, using an iterative localized search. For simple cases it produces the same thing, but in complex cases it is more robust.

It is based on two ideas:

- if the action in consume_optional() is being 'greedy', use

    slots = self._match_arguments_partial([action]+positionals, selected_patterns)

  to determine if this action can share arguments with any of the remaining positionals.  This is similar to how consume_positionals() allocates arguments to the set of positionals.

- try this 'sharing' with the last optional.  If that is not enough, try the penultimate optional as well, and continue working toward the start as needed.

Since the normal parsing is from left to right, figuring out when to start 'sharing' requires some sort of search strategy.  I have moved the start_index loop into a consume_loop() function, and added a switch so it can parse the arguments without invoking take_action() (so arguments are not evaluated, and namespace is not changed).

If there is a suspected 'greed' problem, consume_loop() is called (in test mode) one or more times to determine the right-most optionals to use, and once more (with take_action) to parse and evaluate the arguments.

As in the previous patch this writes a log file for debugging purposes. now has a number of tests for this issue.  

It is more robust than the previous patch, and does not need special handling for things like subparsers and explicit arguments.
Date User Action Args
2013-05-23 16:20:44paul.j3setrecipients: + paul.j3, bethard, wrobell, eric.araujo, catherine, elsdoerfer, Kotan
2013-05-23 16:20:42paul.j3setmessageid: <>
2013-05-23 16:20:42paul.j3linkissue9338 messages
2013-05-23 16:20:41paul.j3create