Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2326,7 +2326,7 @@ def _get_option_tuples(self, option_string):
action = self._option_string_actions[option_string]
tup = action, option_string, '', short_explicit_arg
result.append(tup)
elif option_string.startswith(option_prefix):
elif self.allow_abbrev and option_string.startswith(option_prefix):
action = self._option_string_actions[option_string]
tup = action, option_string, None, None
result.append(tup)
Expand Down
17 changes: 17 additions & 0 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,23 @@ class TestOptionalsDisallowLongAbbreviationPrefixChars(ParserTestCase):
]


class TestOptionalsDisallowSingleDashLongAbbreviation(ParserTestCase):
"""Do not allow abbreviations of long options at all"""

parser_signature = Sig(allow_abbrev=False)
argument_signatures = [
Sig('-foo'),
Sig('-foodle', action='store_true'),
Sig('-foonly'),
]
failures = ['-foon 3', '-food', '-food -foo 2']
successes = [
('', NS(foo=None, foodle=False, foonly=None)),
('-foo 3', NS(foo='3', foodle=False, foonly=None)),
('-foonly 7 -foodle -foo 2', NS(foo='2', foodle=True, foonly='7')),
]


class TestDisallowLongAbbreviationAllowsShortGrouping(ParserTestCase):
"""Do not allow abbreviations of long options at all"""

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix disallowing abbreviation of single-dash long options in :mod:`argparse`
with ``allow_abbrev=False``.
Loading