Index: Lib/argparse.py =================================================================== --- Lib/argparse.py (révision 86945) +++ Lib/argparse.py (copie de travail) @@ -1079,8 +1079,9 @@ try: parser = self._name_parser_map[parser_name] except KeyError: - tup = parser_name, ', '.join(self._name_parser_map) - msg = _('unknown parser %r (choices: %s)' % tup) + args = {'parser_name': parser_name, + 'choices': ', '.join(self._name_parser_map)} + msg = _('unknown parser %(parser_name)r (choices: %(choices)s)') % args raise ArgumentError(self, msg) # parse all the remaining options into the namespace @@ -1380,10 +1381,10 @@ for option_string in args: # error on strings that don't start with an appropriate prefix if not option_string[0] in self.prefix_chars: - msg = _('invalid option string %r: ' - 'must start with a character %r') - tup = option_string, self.prefix_chars - raise ValueError(msg % tup) + args = {'option': option_string, 'character': self.prefix_chars} + msg = _('invalid option string %(option)r: ' + 'must start with a character %(character)r') + raise ValueError(msg % args) # strings starting with two prefix characters are long options option_strings.append(option_string) @@ -2049,8 +2050,9 @@ if len(option_tuples) > 1: options = ', '.join([option_string for action, option_string, explicit_arg in option_tuples]) - tup = arg_string, options - self.error(_('ambiguous option: %s could match %s') % tup) + args = {'option': arg_string, 'matches': options} + msg = _('ambiguous option: %(option)s could match %(matches)s') + self.error(msg % args) # if exactly one action matched, this segmentation is good, # so return the parsed action @@ -2229,8 +2231,9 @@ # TypeErrors or ValueErrors also indicate errors except (TypeError, ValueError): name = getattr(action.type, '__name__', repr(action.type)) - msg = _('invalid %s value: %r') - raise ArgumentError(action, msg % (name, arg_string)) + args = {'name': name, 'arg_string': arg_string} + msg = _('invalid %(name)s value: %(arg_string)r') + raise ArgumentError(action, msg % args) # return the converted value return result @@ -2238,9 +2241,10 @@ 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) + args = {'value': value, + 'choices': ', '.join(map(repr, action.choices))} + msg = _('invalid choice: %(value)r (choose from %(choices)s)') + raise ArgumentError(action, msg % args) # ======================= # Help-formatting methods @@ -2332,4 +2336,5 @@ should either exit or raise an exception. """ self.print_usage(_sys.stderr) - self.exit(2, _('%s: error: %s\n') % (self.prog, message)) + args = {'program_name': self.prog, 'message': message} + self.exit(2, _('%(program_name)s: error: %(message)s\n') % args)