[issue34409] Add a way to customize iteration over fields in asdict() for the nested dataclasses

2018-09-11 Thread mkurnikov
mkurnikov added the comment: Cleanest thing I could think of is: 1. Extract dataclass_to_dict function from _asdict_inner as: def dataclass_asdict(obj, dict_factory): result = [] for f in fields(obj): value = _asdict_inner(getattr(obj, f.name), dict_factory

[issue34409] Add a way to customize iteration over fields in asdict() for the nested dataclasses

2018-08-14 Thread mkurnikov
mkurnikov added the comment: from pprint import pprint from typing import List, Any, Dict import dataclasses from dataclasses import field def service_interface_dict_factory(obj: Any) -> Dict[str, Any]: print(type(obj)) # <- type(obj) here is a list, but there's no way to unde

[issue34409] Add a way to customize iteration over fields in asdict() for the nested dataclasses

2018-08-14 Thread mkurnikov
New submission from mkurnikov : Suppose I have two dataclasses: @dataclass class NestedDataclass(object): name: str options: Dict[str, Any] = field(default_factory=dict) @dataclass class RootDataclass(object): nested_list: List[NestedDataclass] I want a dict under the key