mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-26967: fix flag grouping with allow_abbrev=False (GH-14316)
The `allow_abbrev` option for ArgumentParser is documented and intended to disable support for unique prefixes of --options, which may sometimes be ambiguous due to deferred parsing. However, the initial implementation also broke parsing of grouped short flags, such as `-ab` meaning `-a -b` (or `-a=b`). Checking the argument for a leading `--` before rejecting it fixes this. This was prompted by pytest-dev/pytest#5469, so a backport to at least 3.8 would be great 😄 And this is my first PR to CPython, so please let me know if I've missed anything! https://bugs.python.org/issue26967
This commit is contained in:
parent
014847034b
commit
dffca9e925
5 changed files with 28 additions and 1 deletions
|
@ -785,6 +785,25 @@ class TestOptionalsDisallowLongAbbreviation(ParserTestCase):
|
|||
('--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
|
||||
# ================
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue