From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Sat, 6 Jun 2020 02:31:18 +0000 (-0700) Subject: bpo-40862: Raise TypeError when const is given to argparse.BooleanOptionalAction... X-Git-Tag: v3.9.0b2~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d5e7348e4105d1d4a1c5bd1087f61041532ecbf3;p=thirdparty%2FPython%2Fcpython.git bpo-40862: Raise TypeError when const is given to argparse.BooleanOptionalAction (GH-20623) (GH-20664) --- diff --git a/Lib/argparse.py b/Lib/argparse.py index 2677ef63e9e5..2fb1da59f942 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 e82a0c39c21a..22cae626ccc2 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"""