| Total Complexity | 4 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from typing import Optional |
||
| 2 | |||
| 3 | from jsons.exceptions import DeserializationError |
||
| 4 | |||
| 5 | |||
| 6 | def default_primitive_deserializer(obj: object, |
||
| 7 | cls: Optional[type] = None, |
||
| 8 | **kwargs) -> object: |
||
| 9 | """ |
||
| 10 | Deserialize a primitive: it simply returns the given primitive. |
||
| 11 | :param obj: the value that is to be deserialized. |
||
| 12 | :param cls: not used. |
||
| 13 | :param kwargs: not used. |
||
| 14 | :return: ``obj``. |
||
| 15 | """ |
||
| 16 | result = obj |
||
| 17 | if obj is not None and not isinstance(obj, cls): |
||
| 18 | try: |
||
| 19 | result = cls(obj) |
||
| 20 | except ValueError as err: |
||
| 21 | raise DeserializationError( |
||
| 22 | 'Could not cast "{}" into "{}"'.format(obj, cls.__name__), |
||
| 23 | obj, cls) from err |
||
| 24 | return result |
||
| 25 |