Passed
Pull Request — master (#17)
by Ramon
50s
created

default_string_deserializer()   A

Complexity

Conditions 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 16
rs 10
c 0
b 0
f 0
cc 2
nop 3
1
from datetime import datetime
2
from typing import Optional
3
from jsons.exceptions import DeserializationError
4
from jsons._main_impl import load
5
6
7
def default_string_deserializer(obj: str,
8
                                cls: Optional[type] = None,
9
                                **kwargs) -> object:
10
    """
11
    Deserialize a string. If the given ``obj`` can be parsed to a date, a
12
    ``datetime`` instance is returned.
13
    :param obj: the string that is to be deserialized.
14
    :param cls: not used.
15
    :param kwargs: any keyword arguments.
16
    :return: the deserialized obj.
17
    """
18
    try:
19
        result = load(obj, datetime, **kwargs)
20
    except DeserializationError:
21
        result = obj
22
    return result
23