8000 bpo-40862: Raise TypeError when const is given to argparse.BooleanOpt… · python/cpython@b084d1b · GitHub
[go: up one dir, main page]

Skip to content

Commit b084d1b

Browse files
authored
bpo-40862: Raise TypeError when const is given to argparse.BooleanOptionalAction (GH-20623)
1 parent 45af786 commit b084d1b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Lib/argparse.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,6 @@ class BooleanOptionalAction(Action):
857857
def __init__(self,
858858
option_strings,
859859
dest,
860-
const=None,
861860
default=None,
862861
type=None,
863862
choices=None,

Lib/test/test_argparse.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,14 @@ class TestBooleanOptionalAction(ParserTestCase):
700700
('--no-foo --foo', NS(foo=True)),
701701
]
702702

703+
def test_const(self):
704+
# See bpo-40862
705+
parser = argparse.ArgumentParser()
706+
with self.assertRaises(TypeError) as cm:
707+
parser.add_argument('--foo', const=True, action=argparse.BooleanOptionalAction)
708+
709+
self.assertIn("got an unexpected keyword argument 'const'", str(cm.exception))
710+
703711
class TestBooleanOptionalActionRequired(ParserTestCase):
704712
"""Tests BooleanOptionalAction required"""
705713

0 commit comments

Comments
 (0)
0