Index: Lib/argparse.py =================================================================== --- Lib/argparse.py (revisione 86635) +++ Lib/argparse.py (copia locale) @@ -1919,17 +1919,12 @@ # if we didn't consume all the argument strings, there were extras extras.extend(arg_strings[stop_index:]) - # if we didn't use all the Positional objects, there were too few - # arg strings supplied. - if positionals: - self.error(_('too few arguments')) - # make sure all required actions were present - for action in self._actions: - if action.required: - if action not in seen_actions: - name = _get_action_name(action) - self.error(_('argument %s is required') % name) + required_actions = [_get_action_name(action) for action in self._actions + if action.required and action not in seen_actions] + if required_actions: + self.error(_('the following arguments are required: %s') % + ', '.join(required_actions)) # make sure all required groups had one option present for group in self._mutually_exclusive_groups: Index: Lib/test/test_argparse.py =================================================================== --- Lib/test/test_argparse.py (revisione 86635) +++ Lib/test/test_argparse.py (copia locale) @@ -4277,6 +4277,28 @@ else: self.fail() +# ========================== +# ArgumentContentError tests +# ========================== + +class TestArgumentContentError(TestCase): + """Test that the names of the missing args are included in + the error message.""" + + def test_missingoptions(self): + parser = ErrorRaisingArgumentParser(prog='PROG') + parser.add_argument('x', type=str) + parser.add_argument('-y', type=int, required=True) + parser.add_argument('z', type=str, nargs='+') + + with self.assertRaisesRegexp(ArgumentParserError, 'x, -y, z'): + parser.parse_args([]) + with self.assertRaisesRegexp(ArgumentParserError, '-y, z'): + parser.parse_args(['myXargument']) + with self.assertRaisesRegexp(ArgumentParserError, 'error:[\w ]+: z'): + parser.parse_args(['myXargument', '-y1']) + + # ====================== # parse_known_args tests # ======================