Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow type_hooks for substituted objects of the same parent type #219

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
6 changes: 4 additions & 2 deletions dacite/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ def from_dict(data_class: Type[T], data: Data, config: Optional[Config] = None)
def _build_value(type_: Type, data: Any, config: Config) -> Any:
if is_init_var(type_):
type_ = extract_init_var(type_)
if type_ in config.type_hooks:
data = config.type_hooks[type_](data)
if not is_union(type_):
for th_type, func in config.type_hooks.items():
if is_subclass(th_type, type_):
data = func(data)
if is_optional(type_) and data is None:
return data
if is_union(type_):
Expand Down