-
Notifications
You must be signed in to change notification settings - Fork 13
/
has_dict.py
40 lines (33 loc) · 1.15 KB
/
has_dict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.
"""Interface for classes to serialize to dictionary."""
from abc import ABC, abstractmethod
__author__ = "Jan Janssen"
__copyright__ = (
"Copyright 2023, Max-Planck-Institut für Eisenforschung GmbH - "
"Computational Materials Design (CM) Department"
)
__version__ = "1.0"
__maintainer__ = "Jan Janssen"
__email__ = "janssen@mpie.de"
__status__ = "production"
__date__ = "Dec 20, 2023"
class HasDict(ABC):
__dict_version__ = "0.1.0"
@abstractmethod
def from_dict(self, obj_dict: dict, version: str = None):
pass
@abstractmethod
def to_dict(self):
pass
def _type_to_dict(self):
type_dict = {
"NAME": self.__class__.__name__,
"TYPE": str(type(self)),
"OBJECT": self.__class__.__name__, # unused alias
"DICT_VERSION": self.__dict_version__,
}
if hasattr(self, "__version__"):
type_dict["VERSION"] = self.__version__
return type_dict