MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _get_value

Method _get_value

tools/python-3.11.9-amd64/Lib/argparse.py:2531–2555  ·  view source on GitHub ↗
(self, action, arg_string)

Source from the content-addressed store, hash-verified

2529 return value
2530
2531 def _get_value(self, action, arg_string):
2532 type_func = self._registry_get('type', action.type, action.type)
2533 if not callable(type_func):
2534 msg = _('%r is not callable')
2535 raise ArgumentError(action, msg % type_func)
2536
2537 # convert the value to the appropriate type
2538 try:
2539 result = type_func(arg_string)
2540
2541 # ArgumentTypeErrors indicate errors
2542 except ArgumentTypeError as err:
2543 name = getattr(action.type, '__name__', repr(action.type))
2544 msg = str(err)
2545 raise ArgumentError(action, msg)
2546
2547 # TypeErrors or ValueErrors also indicate errors
2548 except (TypeError, ValueError):
2549 name = getattr(action.type, '__name__', repr(action.type))
2550 args = {'type': name, 'value': arg_string}
2551 msg = _('invalid %(type)s value: %(value)r')
2552 raise ArgumentError(action, msg % args)
2553
2554 # return the converted value
2555 return result
2556
2557 def _check_value(self, action, value):
2558 # converted value must be one of the choices (if specified)

Callers 2

_parse_known_argsMethod · 0.95
_get_valuesMethod · 0.95

Calls 5

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

Tested by

no test coverage detected