@@ -45,13 +45,16 @@ def __getattr__(self, attr):
45
45
class ModelComponent (object ):
46
46
"""Model component base class"""
47
47
48
- def __init__ (self , model ):
48
+ def __new__ (cls , * args , ** kwargs ):
49
+ instance = super (ModelComponent , cls ).__new__ (cls )
49
50
# This class overrides __setattr__ with a method that requires
50
51
# the `pars` and `pars_dict` attrs to be visible. So do this
51
52
# with the super (object) method right away.
52
- super (ModelComponent , self ).__setattr__ ("pars" , [])
53
- super (ModelComponent , self ).__setattr__ ("pars_dict" , {})
53
+ super (ModelComponent , instance ).__setattr__ ("pars" , [])
54
+ super (ModelComponent , instance ).__setattr__ ("pars_dict" , {})
55
+ return instance
54
56
57
+ def __init__ (self , model ):
55
58
self .model = model
56
59
self .n_mvals = 0
57
60
self .predict = False # Predict values for this model component
@@ -81,21 +84,13 @@ def __getattr__(self, attr):
81
84
if attr == "trait_names" :
82
85
return []
83
86
84
- # Ensure pars_dict is initialized before accessing it
85
- if "pars_dict" not in self .__dict__ :
86
- super (ModelComponent , self ).__setattr__ ("pars_dict" , {})
87
-
88
87
if attr in self .pars_dict :
89
88
return self .pars_dict [attr ].val
90
89
else :
91
90
# This will raise the expected AttributeError exception
92
91
return super (ModelComponent , self ).__getattribute__ (attr )
93
92
94
93
def __setattr__ (self , attr , val ):
95
- # Ensure pars_dict is initialized before accessing it
96
- if "pars_dict" not in self .__dict__ :
97
- super (ModelComponent , self ).__setattr__ ("pars_dict" , {})
98
-
99
94
if attr in self .pars_dict :
100
95
self .pars_dict [attr ].val = val
101
96
else :
0 commit comments