diff -r 4fae1004fc58 argparse.py --- a/argparse.py Sat Aug 20 10:31:36 2011 +0200 +++ b/argparse.py Sat Aug 20 10:34:08 2011 +0200 @@ -1071,14 +1071,18 @@ parser_name = values[0] arg_strings = values[1:] + # select the parser + parser = None + for p in self._name_parser_map: + if p.startswith(parser_name): + parser = self._name_parser_map[p] + break + # set the parser name if requested if self.dest is not SUPPRESS: - setattr(namespace, self.dest, parser_name) + setattr(namespace, self.dest, p) - # select the parser - try: - parser = self._name_parser_map[parser_name] - except KeyError: + if not parser: tup = parser_name, ', '.join(self._name_parser_map) msg = _('unknown parser %r (choices: %s)' % tup) raise ArgumentError(self, msg) @@ -2239,10 +2243,16 @@ def _check_value(self, action, value): # converted value must be one of the choices (if specified) - if action.choices is not None and value not in action.choices: - tup = value, ', '.join(map(repr, action.choices)) - msg = _('invalid choice: %r (choose from %s)') % tup - raise ArgumentError(action, msg) + if action.choices is not None: + ac = [ax for ax in action.choices.keys() if ax.startswith(value)] + if len(ac) == 0: + tup = value, ', '.join(map(repr, action.choices)) + msg = _('invalid choice: %r (choose from %s)') % tup + raise ArgumentError(action, msg) + elif len(ac) > 1: + tup = value, ', '.join(ac) + msg = _('ambigous choice: %r (choose from %s)') % tup + raise ArgumentError(action, msg) # ======================= # Help-formatting methods