.. versionchanged:: 3.5
*allow_abbrev* parameter was added.
+ .. versionchanged:: 3.8
+ In previous versions, *allow_abbrev* also disabled grouping of short
+ flags such as ``-vv`` to mean ``-v -v``.
+
The following sections describe how each of these are used.
action = self._option_string_actions[option_string]
return action, option_string, explicit_arg
- if self.allow_abbrev:
+ if self.allow_abbrev or not arg_string.startswith('--'):
# search through all possible prefixes of the option string
# and all actions in the parser for possible interpretations
option_tuples = self._get_option_tuples(arg_string)
('--foonly 7 --foodle --foo 2', NS(foo='2', foodle=True, foonly='7')),
]
+
+class TestDisallowLongAbbreviationAllowsShortGrouping(ParserTestCase):
+ """Do not allow abbreviations of long options at all"""
+
+ parser_signature = Sig(allow_abbrev=False)
+ argument_signatures = [
+ Sig('-r'),
+ Sig('-c', action='count'),
+ ]
+ failures = ['-r', '-c -r']
+ successes = [
+ ('', NS(r=None, c=None)),
+ ('-ra', NS(r='a', c=None)),
+ ('-rcc', NS(r='cc', c=None)),
+ ('-cc', NS(r=None, c=2)),
+ ('-cc -ra', NS(r='a', c=2)),
+ ('-ccrcc', NS(r='cc', c=2)),
+ ]
+
# ================
# Positional tests
# ================
--- /dev/null
+An :class:`~argparse.ArgumentParser` with ``allow_abbrev=False`` no longer
+disables grouping of short flags, such as ``-vv``, but only disables
+abbreviation of long flags as documented. Patch by Zac Hatfield-Dodds.