I'm using dataclass and asdict from dataclasses, and I find that asdict doesn't work as I would expect when I introduce inheritance.
I use dataclasses to help me create dictionaries from classes so I can pass them into django.shortcuts.render.
from dataclasses import dataclass
from dataclasses import asdict
@dataclass
class Base:
name: str
class Test(Base):
def __init__(self, age, *args, **kwargs):
self.age = age
super(Test, self).__init__(*args, **kwargs)
test = Test(age=20, name="john doe")
print(asdict(test))
I would expect the output to be
{"age": 20, "name": "john doe"}
But what I get is only the keyword-value from the base-class
{"name": "john doe"}