gh-138525: raise error when BooleanOptionalAction used with prefix_chars without '-' by mattwang44 · Pull Request #138526 · python/cpython · GitHub
Skip to content
Closed
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
11 changes: 11 additions & 0 deletions Lib/argparse.py
5 changes: 5 additions & 0 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,11 @@ def test_invalid_name(self):
self.assertEqual(str(cm.exception),
"invalid option name '--no-foo' for BooleanOptionalAction")

def test_prefix_chars_incompatibility(self):
parser = argparse.ArgumentParser(prefix_chars='+')
with self.assertRaisesRegex(ValueError, "BooleanOptionalAction requires '-' in prefix_chars."):
parser.add_argument('++foo', action=argparse.BooleanOptionalAction)

class TestBooleanOptionalActionRequired(ParserTestCase):
"""Tests BooleanOptionalAction required"""

Expand Down
Loading