MCPcopy Index your code
hub / github.com/RustPython/RustPython / _check_value

Method _check_value

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

Source from the content-addressed store, hash-verified

2666 return result
2667
2668 def _check_value(self, action, value):
2669 # converted value must be one of the choices (if specified)
2670 choices = action.choices
2671 if choices is None:
2672 return
2673
2674 if isinstance(choices, str):
2675 choices = iter(choices)
2676
2677 if value not in choices:
2678 args = {'value': str(value),
2679 'choices': ', '.join(map(str, action.choices))}
2680 msg = _('invalid choice: %(value)r (choose from %(choices)s)')
2681
2682 if self.suggest_on_error and isinstance(value, str):
2683 if all(isinstance(choice, str) for choice in action.choices):
2684 import difflib
2685 suggestions = difflib.get_close_matches(value, action.choices, 1)
2686 if suggestions:
2687 args['closest'] = suggestions[0]
2688 msg = _('invalid choice: %(value)r, maybe you meant %(closest)r? '
2689 '(choose from %(choices)s)')
2690
2691 raise ArgumentError(action, msg % args)
2692
2693 # =======================
2694 # Help-formatting methods

Callers 1

_get_valuesMethod · 0.95

Calls 7

isinstanceFunction · 0.85
iterFunction · 0.85
strFunction · 0.85
allFunction · 0.85
ArgumentErrorClass · 0.70
_Function · 0.50
joinMethod · 0.45

Tested by

no test coverage detected