Load the serializable class from a filepath. Args: filepath (str): the path of file Raises: TypeError: the pickled file must be `type(cls)` Returns: `type(cls)`: the instance of `type(cls)`
(cls, filepath)
| 134 | |
| 135 | @classmethod |
| 136 | def load(cls, filepath): |
| 137 | """ |
| 138 | Load the serializable class from a filepath. |
| 139 | |
| 140 | Args: |
| 141 | filepath (str): the path of file |
| 142 | |
| 143 | Raises: |
| 144 | TypeError: the pickled file must be `type(cls)` |
| 145 | |
| 146 | Returns: |
| 147 | `type(cls)`: the instance of `type(cls)` |
| 148 | """ |
| 149 | with open(filepath, "rb") as f: |
| 150 | object = cls.get_backend().load(f) |
| 151 | if isinstance(object, cls): |
| 152 | return object |
| 153 | else: |
| 154 | raise TypeError(f"The instance of {type(object)} is not a valid `{type(cls)}`!") |
| 155 | |
| 156 | @classmethod |
| 157 | def get_backend(cls): |
no test coverage detected