(self, action, arg_string)
| 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) |
no test coverage detected