28
28
from .Variable import Parameter
29
29
30
30
if TYPE_CHECKING :
31
- from easyscience .Utils . typing import C
32
- from easyscience .Utils . typing import V
33
- from easyscience .Utils . typing import iF
31
+ from easyscience .fitting . Constraints import C
32
+ from easyscience .Objects . Inferface import iF
33
+ from easyscience .Objects . Variable import V
34
34
35
35
36
36
class BasedBase (ComponentSerializer ):
@@ -41,10 +41,10 @@ class BasedBase(ComponentSerializer):
41
41
def __init__ (self , name : str , interface : Optional [iF ] = None , unique_name : Optional [str ] = None ):
42
42
self ._global_object = global_object
43
43
if unique_name is None :
44
- unique_name = self ._unique_name_generator ( )
44
+ unique_name = self ._global_object . generate_unique_name ( self . __class__ . __name__ )
45
45
self ._unique_name = unique_name
46
46
self ._name = name
47
- self ._global_object .map .add_vertex (self , obj_type = " created" )
47
+ self ._global_object .map .add_vertex (self , obj_type = ' created' )
48
48
self .interface = interface
49
49
self .user_data : dict = {}
50
50
@@ -69,16 +69,16 @@ def __reduce__(self):
69
69
70
70
@property
71
71
def unique_name (self ) -> str :
72
- """ Get the unique name of the object."""
72
+ """Get the unique name of the object."""
73
73
return self ._unique_name
74
74
75
75
@unique_name .setter
76
76
def unique_name (self , new_unique_name : str ):
77
- """ Set a new unique name for the object. The old name is still kept in the map.
78
-
77
+ """Set a new unique name for the object. The old name is still kept in the map.
78
+
79
79
:param new_unique_name: New unique name for the object"""
80
80
if not isinstance (new_unique_name , str ):
81
- raise TypeError (" Unique name has to be a string." )
81
+ raise TypeError (' Unique name has to be a string.' )
82
82
self ._unique_name = new_unique_name
83
83
self ._global_object .map .add_vertex (self )
84
84
@@ -206,18 +206,6 @@ def get_fit_parameters(self) -> Union[List[Parameter], List[NewParameter]]:
206
206
fit_list .append (item )
207
207
return fit_list
208
208
209
- def _unique_name_generator (self ) -> str :
210
- """
211
- Generate a generic unique name for the object using the class name and a global iterator.
212
- """
213
- class_name = self .__class__ .__name__
214
- iterator_string = str (self ._global_object .map ._get_name_iterator (class_name ))
215
- name = class_name + "_" + iterator_string
216
- while name in self ._global_object .map .vertices ():
217
- iterator_string = str (self ._global_object .map ._get_name_iterator (class_name ))
218
- name = class_name + "_" + iterator_string
219
- return name
220
-
221
209
def __dir__ (self ) -> Iterable [str ]:
222
210
"""
223
211
This creates auto-completion and helps out in iPython notebooks.
@@ -226,7 +214,6 @@ def __dir__(self) -> Iterable[str]:
226
214
"""
227
215
new_class_objs = list (k for k in dir (self .__class__ ) if not k .startswith ('_' ))
228
216
return sorted (new_class_objs )
229
-
230
217
231
218
232
219
if TYPE_CHECKING :
@@ -267,7 +254,7 @@ def __init__(
267
254
self ._kwargs = kwargs
268
255
for key in kwargs .keys ():
269
256
if key in known_keys :
270
- raise AttributeError (" Kwargs cannot overwrite class attributes in BaseObj." )
257
+ raise AttributeError (' Kwargs cannot overwrite class attributes in BaseObj.' )
271
258
if issubclass (type (kwargs [key ]), (BasedBase , Descriptor , DescriptorBase )) or 'BaseCollection' in [
272
259
c .__name__ for c in type (kwargs [key ]).__bases__
273
260
]:
0 commit comments