]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40862: Raise TypeError when const is given to argparse.BooleanOptionalAction...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 6 Jun 2020 02:31:18 +0000 (19:31 -0700)
committerGitHub <noreply@github.com>
Sat, 6 Jun 2020 02:31:18 +0000 (19:31 -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"""