Skip to content

Commit

Permalink
bpo-40862: Raise TypeError when const is given to argparse.BooleanOpt…
Browse files Browse the repository at this point in the history
…ionalAction (GH-20623)
  • Loading branch information
remilapeyre authored Jun 5, 2020
1 parent 45af786 commit b084d1b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 0 additions & 1 deletion Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,6 @@ class BooleanOptionalAction(Action):
def __init__(self,
option_strings,
dest,
const=None,
default=None,
type=None,
choices=None,
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,14 @@ class TestBooleanOptionalAction(ParserTestCase):
('--no-foo --foo', NS(foo=True)),
]

def test_const(self):
# See bpo-40862
parser = argparse.ArgumentParser()
with self.assertRaises(TypeError) as cm:
parser.add_argument('--foo', const=True, action=argparse.BooleanOptionalAction)

self.assertIn("got an unexpected keyword argument 'const'", str(cm.exception))

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

Expand Down

0 comments on commit b084d1b

Please sign in to comment.