def override_from_json()

in summarize_from_feedback/utils/hyperparams.py [0:0]


    def override_from_json(self, json_val, key=""):
        typemap = _type_map(type(self))

        for k, v in json_val.items():
            if k not in typemap:
                raise AttributeError(f"{self} has no attribute {k}")
            t = typemap[k]
            hps_cls = _hparam_constructible_class(t)
            if hps_cls is not None and isinstance(v, dict):
                old_v = getattr(self, k)
                # initialize constructor, overwriting value if it's not the correct class (can happen with Unions)
                if old_v is None or not isinstance(old_v, hps_cls):
                    setattr(self, k, hps_cls())
                getattr(self, k).override_from_json(v, key + "." + k)
            else:
                new_v = _construct_from_json(t, v, key + "." + k)
                check_type(k, new_v, t)
                setattr(self, k, new_v)