bpo-40862: Raise TypeError when const is given to argparse.BooleanOptionalAction (GH-20623) (GH-20664)

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 @@
         ('--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"""