| Conditions | 3 |
| Total Lines | 19 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | from datetime import datetime |
||
| 9 | def default_string_deserializer(obj: str, |
||
| 10 | cls: Optional[type] = None, |
||
| 11 | **kwargs) -> object: |
||
| 12 | """ |
||
| 13 | Deserialize a string. If the given ``obj`` can be parsed to a date, a |
||
| 14 | ``datetime`` instance is returned. |
||
| 15 | :param obj: the string that is to be deserialized. |
||
| 16 | :param cls: not used. |
||
| 17 | :param kwargs: any keyword arguments. |
||
| 18 | :return: the deserialized obj. |
||
| 19 | """ |
||
| 20 | target_is_str = cls is str and not kwargs.get('_inferred_cls') |
||
| 21 | if target_is_str: |
||
| 22 | return str(obj) |
||
| 23 | try: |
||
| 24 | result = load(obj, datetime, **kwargs) |
||
| 25 | except DeserializationError: |
||
| 26 | result = default_primitive_deserializer(obj, str) |
||
| 27 | return result |
||
| 28 |