| Conditions | 6 |
| Total Lines | 10 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | from typing import Literal, Any, get_args |
||
| 5 | def default_literal_deserializer(obj: Any, cls: Literal, *, strictly_equal_literal: bool = False, **kwargs): |
||
| 6 | for literal_value in get_args(cls): |
||
| 7 | value_equal = obj == literal_value |
||
| 8 | type_equal = type(obj) == type(literal_value) |
||
| 9 | if value_equal and (not strictly_equal_literal or type_equal): |
||
| 10 | break |
||
| 11 | else: |
||
| 12 | err_msg = 'Could not match the object "{}" to the Literal: {}'.format(obj, cls) |
||
| 13 | raise DeserializationError(err_msg, obj, None) |
||
| 14 | return literal_value |
||
| 15 |