summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index f428512..a671c8b 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -2552,11 +2552,15 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
def _check_value(self, action, value):
# converted value must be one of the choices (if specified)
- if action.choices is not None and value not in action.choices:
- args = {'value': value,
- 'choices': ', '.join(map(repr, action.choices))}
- msg = _('invalid choice: %(value)r (choose from %(choices)s)')
- raise ArgumentError(action, msg % args)
+ choices = action.choices
+ if choices is not None:
+ if isinstance(choices, str):
+ choices = iter(choices)
+ if value not in choices:
+ args = {'value': value,
+ 'choices': ', '.join(map(repr, action.choices))}
+ msg = _('invalid choice: %(value)r (choose from %(choices)s)')
+ raise ArgumentError(action, msg % args)
# =======================
# Help-formatting methods