How to use the dacite.dataclasses.DefaultValueNotFoundError 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 / tests / View on Github external
def test_get_default_value_for_field_without_default_value():
    class X:
        i: int

    with pytest.raises(DefaultValueNotFoundError):
github konradhalas / dacite / dacite / View on Github external
                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)
github konradhalas / dacite / dacite / View on Github external
def get_default_value_for_field(field: Field) -> Any:
    if field.default != MISSING:
        return field.default
    elif field.default_factory != MISSING:  # type: ignore
        return field.default_factory()  # type: ignore
    elif is_optional(field.type):
        return None
    raise DefaultValueNotFoundError()