dacite icon indicating copy to clipboard operation
dacite copied to clipboard

Add missing value factory for from_dict()

Open evan0greenup opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. When there is missing value in dict, it will raise Error, this is good for majority scenario but sometimes user want to give the attribute with default value for the specific type via default factory callable.

It would be nice to add this support in Config.

Describe the solution you'd like Add default_factory kwarg in Config which is type dict[type, Callable[[], Any]. the return value of callable is the instance of the key type.

The default value of default_factory is None, which will raise Error when the key is missing.

When the missing value is the type beyond the keys in default_factory, it will also raise Error.

Describe alternatives you've considered ...

Additional context

evan0greenup avatar Jul 08 '23 12:07 evan0greenup