diff options
author | RĂ©mi Lapeyre <remi.lapeyre@lenstra.fr> | 2020-06-05 22:00:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-05 22:00:42 (GMT) |
commit | b084d1b97e369293d2d2bc0791e2135822c923a8 (patch) | |
tree | c1a7fe68ed0a24fe04baf7a7a6ce02c0bb485d52 | |
parent | 45af786e111aed5f687e1f0d8b45b6a5e678a6bc (diff) | |
download | cpython-b084d1b97e369293d2d2bc0791e2135822c923a8.zip cpython-b084d1b97e369293d2d2bc0791e2135822c923a8.tar.gz cpython-b084d1b97e369293d2d2bc0791e2135822c923a8.tar.bz2 |
bpo-40862: Raise TypeError when const is given to argparse.BooleanOptionalAction (GH-20623)
-rw-r--r-- | Lib/argparse.py | 1 | ||||
-rw-r--r-- | Lib/test/test_argparse.py | 8 |
2 files changed, 8 insertions, 1 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py index 2677ef6..2fb1da5 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -857,7 +857,6 @@ class BooleanOptionalAction(Action): def __init__(self, option_strings, dest, - const=None, default=None, type=None, choices=None, diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index e82a0c3..22cae62 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -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""" |