MCPcopy Index your code
hub / github.com/python/cpython / _check_value

Method _check_value

Lib/argparse.py:2750–2773  ·  view source on GitHub ↗
(self, action, value)

Source from the content-addressed store, hash-verified

2748 return result
2749
2750 def _check_value(self, action, value):
2751 # converted value must be one of the choices (if specified)
2752 choices = action.choices
2753 if choices is None:
2754 return
2755
2756 if isinstance(choices, str):
2757 choices = iter(choices)
2758
2759 if value not in choices:
2760 args = {'value': str(value),
2761 'choices': ', '.join(map(str, action.choices))}
2762 msg = _('invalid choice: %(value)r (choose from %(choices)s)')
2763
2764 if self.suggest_on_error and isinstance(value, str):
2765 if all(isinstance(choice, str) for choice in action.choices):
2766 import difflib
2767 suggestions = difflib.get_close_matches(value, action.choices, 1)
2768 if suggestions:
2769 args['closest'] = suggestions[0]
2770 msg = _('invalid choice: %(value)r, maybe you meant %(closest)r? '
2771 '(choose from %(choices)s)')
2772
2773 raise ArgumentError(action, msg % args)
2774
2775 # =======================
2776 # Help-formatting methods

Callers 1

_get_valuesMethod · 0.95

Calls 4

strFunction · 0.85
ArgumentErrorClass · 0.70
_Function · 0.50
joinMethod · 0.45

Tested by

no test coverage detected