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

jsons.deserializers.default_string   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 13
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A default_string_deserializer() 0 16 2
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