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

Method _get_value

Lib/argparse.py:2726–2748  ·  view source on GitHub ↗
(self, action, arg_string)

Source from the content-addressed store, hash-verified

2724 return value
2725
2726 def _get_value(self, action, arg_string):
2727 type_func = self._registry_get('type', action.type, action.type)
2728 if not callable(type_func):
2729 raise TypeError(f'{type_func!r} is not callable')
2730
2731 # convert the value to the appropriate type
2732 try:
2733 result = type_func(arg_string)
2734
2735 # ArgumentTypeErrors indicate errors
2736 except ArgumentTypeError as err:
2737 msg = str(err)
2738 raise ArgumentError(action, msg)
2739
2740 # TypeErrors or ValueErrors also indicate errors
2741 except (TypeError, ValueError):
2742 name = getattr(action.type, '__name__', repr(action.type))
2743 args = {'type': name, 'value': arg_string}
2744 msg = _('invalid %(type)s value: %(value)r')
2745 raise ArgumentError(action, msg % args)
2746
2747 # return the converted value
2748 return result
2749
2750 def _check_value(self, action, value):
2751 # converted value must be one of the choices (if specified)

Callers 2

_parse_known_argsMethod · 0.95
_get_valuesMethod · 0.95

Calls 4

strFunction · 0.85
_registry_getMethod · 0.80
ArgumentErrorClass · 0.70
_Function · 0.50

Tested by

no test coverage detected