Implement from_dict(cls, data) that builds a dataclass instance from a dict, recursively, using the field type hints:
list[X] builds each element (recursively if X is a dataclass)Optional[X] (i.e. X | None) accepts Nonedata; missing required fields raise TypeErrordata raise TypeErrorint, str, float, bool) must already have the right type (bool is not accepted for int), otherwise raise TypeError mentioning the field nameUnlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.
Start 7-day free trial