How to use the dacite.exceptions.WrongTypeError function in dacite

To help you get started, we’ve selected a few dacite examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github konradhalas / dacite / dacite / View on Github external
def __str__(self) -> str:
        return (
            f'wrong type for field "{self.field_path}" - should be '
            f'"{_name(self.field_type)}" instead of "{_name(type(self.value))}"'

class MissingValueError(DaciteFieldError):
    def __init__(self, field_path: Optional[str] = None):

    def __str__(self) -> str:
        return f'missing value for field "{self.field_path}"'

class UnionMatchError(WrongTypeError):
    def __str__(self) -> str:
        return (
            f'can not match type "{_name(type(self.value))}" to any type '
            f'of "{self.field_path}" union: {_name(self.field_type)}'

class ForwardReferenceError(DaciteError):
    def __init__(self, message: str) -> None:
        self.message = message

    def __str__(self) -> str:
        return f"can not resolve forward reference: {self.message}"
github konradhalas / dacite / dacite / View on Github external
raise UnexpectedDataError(keys=extra_fields)
    for field in data_class_fields:
        field = copy.copy(field)
        field.type = data_class_hints[]
                field_data = data[]
                transformed_value = transform_value(
                    type_hooks=config.type_hooks, cast=config.cast, target_type=field.type, value=field_data
                value = _build_value(type_=field.type, data=transformed_value, config=config)
            except DaciteFieldError as error:
            if config.check_types and not is_instance(value, field.type):
                raise WrongTypeError(, field_type=field.type, value=value)
        except KeyError:
                value = get_default_value_for_field(field)
            except DefaultValueNotFoundError:
                if not field.init:
                raise MissingValueError(
        if field.init:
            init_values[] = value
            post_init_values[] = value

    return create_instance(data_class=data_class, init_values=init_values, post_init_values=post_init_values)