Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if type(json_obj) not in VALID_TYPES:
invalid_type = get_class_name(type(json_obj), fork_inst=fork_inst,
fully_qualified=True)
valid_types = [get_class_name(typ, fork_inst=fork_inst,
fully_qualified=True)
for typ in VALID_TYPES]
msg = ('Invalid type: "{}", only arguments of the following types are '
'allowed: {}'.format(invalid_type, ", ".join(valid_types)))
raise DeserializationError(msg, json_obj, cls)
if json_obj is None:
raise DeserializationError('Cannot load None with strict=True',
json_obj, cls)
cls_from_meta, meta = get_cls_and_meta(json_obj, fork_inst)
meta_hints = meta.get('classes', {}) if meta else {}
return determine_precedence(
cls, cls_from_meta, type(json_obj), inferred_cls), meta_hints
# given obj. Try to obtain the class of this attribute from the meta info
# or from type hints.
cls_key = '/{}'.format(sig_key)
cls_str_from_meta = meta_hints.get(cls_key, None)
new_hints = meta_hints
cls_from_meta = None
if cls_str_from_meta:
cls_from_meta = get_cls_from_str(
cls_str_from_meta, obj, kwargs['fork_inst'])
# Rebuild the class hints: cls_key becomes the new root.
new_hints = {
key.replace(cls_key, '/'): meta_hints[key]
for key in meta_hints
if key != '/'
}
cls_ = determine_precedence(cls=cls, cls_from_meta=cls_from_meta,
cls_from_type=None, inferred_cls=True)
value = load(obj[sig_key], cls_, meta_hints=new_hints, **kwargs)
return value
json_obj: object,
cls: type,
fork_inst: type,
inferred_cls: bool) -> Tuple[type, Optional[dict]]:
# Check if json_obj is of a valid type and return the cls.
if type(json_obj) not in VALID_TYPES:
invalid_type = get_class_name(type(json_obj), fully_qualified=True)
valid_types = [get_class_name(typ, fully_qualified=True)
for typ in VALID_TYPES]
msg = ('Invalid type: "{}", only arguments of the following types are '
'allowed: {}'.format(invalid_type, ", ".join(valid_types)))
raise DeserializationError(msg, json_obj, cls)
cls_from_meta, meta = get_cls_and_meta(json_obj, fork_inst)
meta_hints = meta.get('classes', {}) if meta else {}
return determine_precedence(
cls, cls_from_meta, type(json_obj), inferred_cls), meta_hints