]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40862: Raise TypeError when const is given to argparse.BooleanOptionalAction...
authorRémi Lapeyre <remi.lapeyre@lenstra.fr>
Fri, 5 Jun 2020 22:00:42 +0000 (00:00 +0200)
committerGitHub <noreply@github.com>
Fri, 5 Jun 2020 22:00:42 +0000 (15:00 -0700)
Lib/argparse.py
Lib/test/test_argparse.py

index 2677ef63e9e541f7160b7040655758e2faad3e7c..2fb1da59f942cff7fbfc136ebd08ee8ec14bcbaa 100644 (file)
@@ -857,7 +857,6 @@ class BooleanOptionalAction(Action):
     def __init__(self,
                  option_strings,
                  dest,
-                 const=None,
                  default=None,
                  type=None,
                  choices=None,
index e82a0c39c21a8b0c8dc44a1d1437ed26ef578efd..22cae626ccc2973cf31ce76b72852d6f73a16e94 100644 (file)
@@ -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"""