I have, for example, this class:
from dataclasses import dataclass
@dataclass
class Example:
name: str = "Hello"
size: int = 10
I want to be able to return a dictionary of this class without calling a to_dict function, dict or dataclasses.asdict each time I instantiate, like:
e = Example()
print(e)
{'name': 'Hello', 'size': 5}
What I have tried and did not work is ineriting from dict and callint dict.init inside Example's init, it seems to not recognize the name and size
Is there a nice solution to this?
Editing: my goal is that type(e) will be dict and not str, returning the dict from init is not possible, also, the keys and values should be obtained dynamically, and the values for name and size might change depending on the instantiations