[3.12] gh-63143: Fix parsing mutually exclusive arguments in argparse (GH-124307) (GH-124419)

Arguments with the value identical to the default value (e.g. booleans,
small integers, empty or 1-character strings) are no longer considered
"not present".
(cherry picked from commit 3094cd17b0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-09-24 09:42:34 +02:00 committed by GitHub
parent 1366fff609
commit e57fbe3d2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 120 additions and 9 deletions

View file

@ -1991,9 +1991,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
argument_values = self._get_values(action, argument_strings)
# error if this argument is not allowed with other previously
# seen arguments, assuming that actions that use the default
# value don't really count as "present"
if argument_values is not action.default:
# seen arguments
if action.option_strings or argument_strings:
seen_non_default_actions.add(action)
for conflict_action in action_conflicts.get(action, []):
if conflict_action in seen_non_default_actions: