Fork me on GitHub

bolero.utils.from_dict

bolero.utils.from_dict(config, name=None)[source]

Create an object of a class that is fully specified by a config dict.

This will recursively go through all lists, tuples and dicts that are in the configuration. It will start to construct all objects starting from the leaves. For example

config = {"type": "Class1", "arg1": {"type": "Class2"}}
obj = from_dict(config)

is equivalent to

tmp = Class2()
obj = Class1(arg1=tmp)
Parameters:
config : dict

Configuration dictionary of the object. Contains constructor arguments.

Returns:
object : as specified in the config

The object created from the configuration dictionary or ‘config’.