The action is used to store None, True or False when an argument like --foo or --no-foo is given to the cli so it has no used for this action, but it is accepted without warning:
Python 3.10.0a0 (heads/bpo-wip:6e23a9c82b, Jun 4 2020, 13:41:35)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--foo', const='this_is_not_used', action=argparse.BooleanOptionalAction)
BooleanOptionalAction(option_strings=['--foo', '--no-foo'], dest='foo', nargs=0, const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>> args = parser.parse_args()
>>> args
Namespace(foo=None)
We could either always refuse this argument, or accepted and raise ValueError if it is different than None. The attached PR does the first. |