summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-09-29 07:52:52 (GMT)
committerGitHub <noreply@github.com>2024-09-29 07:52:52 (GMT)
commitdac4ec52866e4068f3ac33b4da1e1a1fe6fc2cba (patch)
tree46d3f6069071f82e2aa3f70cea511a666e0e84ef /Lib/argparse.py
parent61180446eee2aef07b042c7e8892c45afabd1499 (diff)
downloadcpython-dac4ec52866e4068f3ac33b4da1e1a1fe6fc2cba.zip
cpython-dac4ec52866e4068f3ac33b4da1e1a1fe6fc2cba.tar.gz
cpython-dac4ec52866e4068f3ac33b4da1e1a1fe6fc2cba.tar.bz2
gh-53834: Fix support of arguments with choices in argparse (GH-124495)
Positional arguments with nargs equal to '?' or '*' no longer check default against choices. Optional arguments with nargs equal to '?' no longer check const against choices.
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py6
1 files changed, 1 insertions, 5 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 715d2ba..f428512 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -2487,7 +2487,6 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
value = action.default
if isinstance(value, str) and value is not SUPPRESS:
value = self._get_value(action, value)
- self._check_value(action, value)
# when nargs='*' on a positional, if there were no command-line
# args, use the default if it is anything other than None
@@ -2495,11 +2494,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
not action.option_strings):
if action.default is not None:
value = action.default
- self._check_value(action, value)
else:
- # since arg_strings is always [] at this point
- # there is no need to use self._check_value(action, value)
- value = arg_strings
+ value = []
# single argument or optional argument produces a single value
elif len(arg_strings) == 1 and action.nargs in [None, OPTIONAL]: