{"record":{"id":"a547109d3fffff11","repo":"microsoft/qlib","slug":"the-instance-of-type-object-is-not-a-valid-ty","errorCode":null,"errorMessage":"The instance of {type(object)} is not a valid `{type(cls)}`!","messagePattern":"The instance of (.+?) is not a valid `(.+?)`!","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"qlib/utils/serial.py","lineNumber":154,"sourceCode":"    def load(cls, filepath):\n        \"\"\"\n        Load the serializable class from a filepath.\n\n        Args:\n            filepath (str): the path of file\n\n        Raises:\n            TypeError: the pickled file must be `type(cls)`\n\n        Returns:\n            `type(cls)`: the instance of `type(cls)`\n        \"\"\"\n        with open(filepath, \"rb\") as f:\n            object = cls.get_backend().load(f)\n        if isinstance(object, cls):\n            return object\n        else:\n            raise TypeError(f\"The instance of {type(object)} is not a valid `{type(cls)}`!\")\n\n    @classmethod\n    def get_backend(cls):\n        \"\"\"\n        Return the real backend of a Serializable class. The pickle_backend value can be \"pickle\" or \"dill\".\n\n        Returns:\n            module: pickle or dill module based on pickle_backend\n        \"\"\"\n        # NOTE: pickle interface like backend; such as dill\n        if cls.pickle_backend == \"pickle\":\n            return pickle\n        elif cls.pickle_backend == \"dill\":\n            return dill\n        else:\n            raise ValueError(\"Unknown pickle backend, please use 'pickle' or 'dill'.\")\n\n    @staticmethod","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/utils/serial.py#L136-L172","documentation":"Error \"The instance of {type(object)} is not a valid `{type(cls)}`!\" thrown in microsoft/qlib.","triggerScenarios":"This error is raised at qlib/utils/serial.py:154 when the guard condition fails: \"instance is not a valid type\". It triggers when the code path receives input or a state that violates the precondition checked at this point — e.g. an unimplemented abstract method being called, an unsupported argument type/value, or an invalid configuration. To avoid it, satisfy the documented precondition before this call: implement the required method in your subclass, or pass a supported value of the expected type as described by the message.","commonSituations":"See trigger scenarios.","solutions":["Pass an object that is an instance of the expected serializable class.","Reconstruct the object via the class's load/from_config path instead of passing a raw value."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}