I am currently working with dataclasses which a class is a composite of another. The code below should have resulted in an error and it did not.
@dataclass
class kk:
p: int
tr: int
@dataclass
class xx:
x: int
y: int
kq: kk
somkq = kk(p=1, tr=3)
somxx = xx(x=1, y=2, kq=somkq)
print(somkq)
print(somxx)
x_dict = {"x":1, "y":2, "kq":{"pk":1, "tr":3}}
print(xx(**x_dict), asdict(xx(**x_dict)))
My thoughts on why an error should occur:
Per default, xx(**dict_obj)
should have raised a TypeError: __init__() ...
since it was not defined "pk" in kq.