mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-40862: Raise TypeError when const is given to argparse.BooleanOptionalAction (GH-20623) (GH-20664)
This commit is contained in:
parent
15fec5627a
commit
d5e7348e41
2 changed files with 8 additions and 1 deletions
|
@ -857,7 +857,6 @@ class BooleanOptionalAction(Action):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
option_strings,
|
option_strings,
|
||||||
dest,
|
dest,
|
||||||
const=None,
|
|
||||||
default=None,
|
default=None,
|
||||||
type=None,
|
type=None,
|
||||||
choices=None,
|
choices=None,
|
||||||
|
|
|
@ -700,6 +700,14 @@ class TestBooleanOptionalAction(ParserTestCase):
|
||||||
('--no-foo --foo', NS(foo=True)),
|
('--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):
|
class TestBooleanOptionalActionRequired(ParserTestCase):
|
||||||
"""Tests BooleanOptionalAction required"""
|
"""Tests BooleanOptionalAction required"""
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue