@@ -72,6 +72,14 @@ def __init__(self, name=None):
7272 if name :
7373 self .name = name
7474
75+ @property
76+ def __dtype__ (self ):
77+ return "{}/{}" .format ("." .join (self .__class__ .__module__ .split ("." )[:2 ]), self .__class__ .__name__ )
78+
79+ @property
80+ def __data__ (self ):
81+ raise NotImplementedError
82+
7583 def __jsondump__ (self , minimal = False ):
7684 """Return the required information for serialization with the COMPAS JSON serializer.
7785
@@ -86,8 +94,8 @@ def __jsondump__(self, minimal=False):
8694
8795 """
8896 state = {
89- "dtype" : self .dtype ,
90- "data" : self .data ,
97+ "dtype" : self .__dtype__ ,
98+ "data" : self .__data__ ,
9199 }
92100 if minimal :
93101 return state
@@ -114,7 +122,7 @@ def __jsonload__(cls, data, guid=None, name=None):
114122 object
115123
116124 """
117- obj = cls .from_data (data )
125+ obj = cls .__from_data__ (data )
118126 if guid is not None :
119127 obj ._guid = UUID (guid )
120128 if name is not None :
@@ -133,13 +141,22 @@ def __setstate__(self, state):
133141 if "name" in state :
134142 self .name = state ["name" ]
135143
136- @property
137- def dtype ( self ):
138- return "{}/{}" . format ( "." . join ( self . __class__ . __module__ . split ( "." )[: 2 ]), self . __class__ . __name__ )
144+ @classmethod
145+ def __from_data__ ( cls , data ): # type: (dict) -> Data
146+ """Construct an object of this type from the provided data.
139147
140- @property
141- def data (self ):
142- raise NotImplementedError
148+ Parameters
149+ ----------
150+ data : dict
151+ The data dictionary.
152+
153+ Returns
154+ -------
155+ :class:`compas.data.Data`
156+ An instance of this object type if the data contained in the dict has the correct schema.
157+
158+ """
159+ return cls (** data )
143160
144161 def ToString (self ):
145162 """Converts the instance to a string.
@@ -169,34 +186,6 @@ def name(self):
169186 def name (self , name ):
170187 self ._name = name
171188
172- @classmethod
173- def from_data (cls , data ): # type: (dict) -> Data
174- """Construct an object of this type from the provided data.
175-
176- Parameters
177- ----------
178- data : dict
179- The data dictionary.
180-
181- Returns
182- -------
183- :class:`compas.data.Data`
184- An instance of this object type if the data contained in the dict has the correct schema.
185-
186- """
187- return cls (** data )
188-
189- def to_data (self ):
190- """Convert an object to its native data representation.
191-
192- Returns
193- -------
194- dict
195- The data representation of the object as described by the schema.
196-
197- """
198- return self .data
199-
200189 @classmethod
201190 def from_json (cls , filepath ): # type: (...) -> Data
202191 """Construct an object of this type from a JSON file.
@@ -295,7 +284,7 @@ def copy(self, cls=None): # type: (...) -> D
295284 """
296285 if not cls :
297286 cls = type (self )
298- obj = cls .from_data (deepcopy (self .data ))
287+ obj = cls .__from_data__ (deepcopy (self .__data__ ))
299288 obj .name = self .name
300289 return obj # type: ignore
301290
@@ -335,7 +324,7 @@ def sha256(self, as_string=False):
335324 def validate_data (cls , data ):
336325 """Validate the data against the object's data schema.
337326
338- The data is the raw data that can be used to construct an object of this type with the classmethod ``from_data ``.
327+ The data is the raw data that can be used to construct an object of this type with the classmethod ``__from_data__ ``.
339328
340329 Parameters
341330 ----------
0 commit comments