From 053640c0b346f9d394dce70b4e8f4e7943af334b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Lapeyre?= Date: Thu, 4 Jun 2020 14:00:31 +0200 Subject: [PATCH 1/2] Raise TypeError when const is given to argparse.BooleanOptionalAction --- Lib/argparse.py | 1 - Lib/test/test_argparse.py | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/argparse.py b/Lib/argparse.py index 2677ef63e9e541..2fb1da59f942cf 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 e82a0c39c21a8b..1e9f36a118aab2 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-wip + 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""" From 157c08e96eb9b735a4460ee3852f750c44bedcc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Lapeyre?= Date: Thu, 4 Jun 2020 20:58:35 +0200 Subject: [PATCH 2/2] Fix bpo number Co-authored-by: Shantanu --- Lib/test/test_argparse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 1e9f36a118aab2..22cae626ccc297 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -701,7 +701,7 @@ class TestBooleanOptionalAction(ParserTestCase): ] def test_const(self): - # See bpo-wip + # See bpo-40862 parser = argparse.ArgumentParser() with self.assertRaises(TypeError) as cm: parser.add_argument('--foo', const=True, action=argparse.BooleanOptionalAction)