def _from_dictlike_obj(cls: Any, obj: Any, default: Any, use_default: bool) -> Any:
+ # pylint: disable=too-many-branches,too-many-locals
+
# default values
if obj is None and use_default:
return default
return None
else:
raise ValidationException(f"Expected None, found {obj}")
-
+
# Union[*variants] (handles Optional[T] due to the way the typing system works)
elif is_union(cls):
variants = get_generic_type_arguments(cls)
return _from_dictlike_obj(v, obj, ..., False)
except ValidationException:
pass
- raise ValidationException("Union {cls} could not be parsed - parsing of all variants failed")
+ raise ValidationException(f"Union {cls} could not be parsed - parsing of all variants failed")
# after this, there is no place for a None object
elif obj is None:
try:
return cls(obj)
except ValueError as e:
- raise ValidationException("Failed to parse primitive type {cls}, value {obj}", e)
+ raise ValidationException(f"Failed to parse primitive type {cls}, value {obj}", e)
# Literal[T]
elif is_literal(cls):
if obj == expected:
return obj
else:
- raise ValidationException("Literal {cls} is not matched with the value {obj}")
+ raise ValidationException(f"Literal {cls} is not matched with the value {obj}")
# Dict[K,V]
elif is_dict(cls):
for key, val in obj.items()
}
except AttributeError as e:
- raise ValidationException(f"Expected dict-like object, but failed to access its .items() method. Value was {obj}")
+ raise ValidationException(
+ f"Expected dict-like object, but failed to access its .items() method. Value was {obj}", e
+ )
# List[T]
elif is_list(cls):
class _LiteralEnum:
- def __getitem__(self, args: Tuple[Union[str,int,bytes], ...]) -> Any:
+ def __getitem__(self, args: Tuple[Union[str, int, bytes], ...]) -> Any:
lits = tuple(Literal[x] for x in args)
return Union[lits] # pyright: reportGeneralTypeIssues=false
+
LiteralEnum = _LiteralEnum()