comment here
This commit is contained in:
24
.CondaPkg/env/lib/python3.11/site-packages/jsons/deserializers/default_primitive.py
vendored
Normal file
24
.CondaPkg/env/lib/python3.11/site-packages/jsons/deserializers/default_primitive.py
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
from typing import Optional
|
||||
|
||||
from jsons.exceptions import DeserializationError
|
||||
|
||||
|
||||
def default_primitive_deserializer(obj: object,
|
||||
cls: Optional[type] = None,
|
||||
**kwargs) -> object:
|
||||
"""
|
||||
Deserialize a primitive: it simply returns the given primitive.
|
||||
:param obj: the value that is to be deserialized.
|
||||
:param cls: not used.
|
||||
:param kwargs: not used.
|
||||
:return: ``obj``.
|
||||
"""
|
||||
result = obj
|
||||
if obj is not None and not isinstance(obj, cls):
|
||||
try:
|
||||
result = cls(obj)
|
||||
except ValueError as err:
|
||||
raise DeserializationError(
|
||||
'Could not cast "{}" into "{}"'.format(obj, cls.__name__),
|
||||
obj, cls) from err
|
||||
return result
|
||||
Reference in New Issue
Block a user