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
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
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