[issue32756] argparse: parse_known_args: raising exception on unknown arg following known one
paul j3
report at bugs.python.org
Tue Feb 13 21:23:57 EST 2018
paul j3 <ajipanca at gmail.com> added the comment:
This error message is intentional.
In def consume_optional(start_index):
# identify additional optionals in the same arg string
# (e.g. -xyz is the same as -x -y -z if no args are required)
# if the action is a single-dash option and takes no
# arguments, try to parse more single-dash options out
# of the tail of the option string
chars = self.prefix_chars
if arg_count == 0 and option_string[1] not in chars:
action_tuples.append((action, [], option_string))
char = option_string[0]
option_string = char + explicit_arg[0]
new_explicit_arg = explicit_arg[1:] or None
optionals_map = self._option_string_actions
if option_string in optionals_map:
action = optionals_map[option_string]
explicit_arg = new_explicit_arg
else:
msg = _('ignored explicit argument %r')
raise ArgumentError(action, msg % explicit_arg)
In other words, it doesn't just split off that extra character and add it to 'argument_strings' for further handling.
Either 'b' is an argument for the '-a' flag or it is a '-b' flag itself. It can't be a positional or extra.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32756>
_______________________________________
More information about the Python-bugs-list
mailing list