David Caro <david.caro.este...@gmail.com> added the comment:

It is not an issue, it will try to match all the optional parameters, and if 
only one matches, then it will use it:

2110                 elif option_string.startswith(option_prefix):
2111                     action = self._option_string_actions[option_string]
2112                     tup = action, option_string, explicit_arg
2113                     result.append(tup)

and

2057         # if exactly one action matched, this segmentation is good,
2058         # so return the parsed action
2059         elif len(option_tuples) == 1:
2060             option_tuple, = option_tuples
2061             return option_tuple


if you try to add more than one optional parameter that matches the substring, 
it will complain:

>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--superstring')
_StoreAction(option_strings=['--superstring'], dest='superstring', nargs=None, 
const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>> parser.parse_args(['--super','value'])
Namespace(superstring='value')
>>> parser.add_argument('--superstring2')
_StoreAction(option_strings=['--superstring'], dest='superstring', nargs=None, 
const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>> parser.parse_args(['--super','value'])
usage: [-h] [--superstring SUPERSTRING] [--superstring2 SUPERSTRING2]
: error: ambiguous option: --super could match --superstring, --superstring2

----------
resolution:  -> invalid
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10981>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to