(self, action, arg_string)
| 2642 | return value |
| 2643 | |
| 2644 | def _get_value(self, action, arg_string): |
| 2645 | type_func = self._registry_get('type', action.type, action.type) |
| 2646 | if not callable(type_func): |
| 2647 | raise TypeError(f'{type_func!r} is not callable') |
| 2648 | |
| 2649 | # convert the value to the appropriate type |
| 2650 | try: |
| 2651 | result = type_func(arg_string) |
| 2652 | |
| 2653 | # ArgumentTypeErrors indicate errors |
| 2654 | except ArgumentTypeError as err: |
| 2655 | msg = str(err) |
| 2656 | raise ArgumentError(action, msg) |
| 2657 | |
| 2658 | # TypeErrors or ValueErrors also indicate errors |
| 2659 | except (TypeError, ValueError): |
| 2660 | name = getattr(action.type, '__name__', repr(action.type)) |
| 2661 | args = {'type': name, 'value': arg_string} |
| 2662 | msg = _('invalid %(type)s value: %(value)r') |
| 2663 | raise ArgumentError(action, msg % args) |
| 2664 | |
| 2665 | # return the converted value |
| 2666 | return result |
| 2667 | |
| 2668 | def _check_value(self, action, value): |
| 2669 | # converted value must be one of the choices (if specified) |
no test coverage detected