MCPcopy
hub / github.com/tanelpoder/0xtools / _get_value

Method _get_value

lib/0xtools/argparse.py:2261–2284  ·  view source on GitHub ↗
(self, action, arg_string)

Source from the content-addressed store, hash-verified

2259 return value
2260
2261 def _get_value(self, action, arg_string):
2262 type_func = self._registry_get('type', action.type, action.type)
2263 if not _callable(type_func):
2264 msg = _('%r is not callable')
2265 raise ArgumentError(action, msg % type_func)
2266
2267 # convert the value to the appropriate type
2268 try:
2269 result = type_func(arg_string)
2270
2271 # ArgumentTypeErrors indicate errors
2272 except ArgumentTypeError:
2273 name = getattr(action.type, '__name__', repr(action.type))
2274 msg = str(_sys.exc_info()[1])
2275 raise ArgumentError(action, msg)
2276
2277 # TypeErrors or ValueErrors also indicate errors
2278 except (TypeError, ValueError):
2279 name = getattr(action.type, '__name__', repr(action.type))
2280 msg = _('invalid %s value: %r')
2281 raise ArgumentError(action, msg % (name, arg_string))
2282
2283 # return the converted value
2284 return result
2285
2286 def _check_value(self, action, value):
2287 # converted value must be one of the choices (if specified)

Callers 2

_parse_known_argsMethod · 0.95
_get_valuesMethod · 0.95

Calls 3

_callableFunction · 0.85
ArgumentErrorClass · 0.85
_registry_getMethod · 0.80

Tested by

no test coverage detected