New submission from Rémi Lapeyre <remi.lape...@henki.fr>: 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. ---------- components: Library (Lib) messages: 370703 nosy: remi.lapeyre priority: normal severity: normal status: open title: argparse.BooleanOptionalAction accept and silently its the const argument versions: Python 3.10, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue40862> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com