How to use the dacite.dataclasses.create_instance 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_create_instance_with_simple_data_class():
    class X:
        i: int

    instance = create_instance(data_class=X, init_values={"i": 1}, post_init_values={})

    assert instance == X(i=1)
github konradhalas / dacite / tests / View on Github external
def test_create_instance_with_post_init_values():
    class X:
        i: int
        j: int = field(init=False)

    instance = create_instance(data_class=X, init_values={"i": 1}, post_init_values={"j": 2})

    assert instance.i == 1
    assert instance.j == 2
github konradhalas / dacite / dacite / View on Github external
            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)