@@ -69,20 +69,9 @@ def read_object_defs(self):
6969 abstract_objects = {}
7070 for object in doc ["objects" ]:
7171 if "abstract" in object :
72- abstract_objects [object ["object" ]] = object
72+ self . abstract_objects [object ["object" ]] = object
7373
7474 for object in doc ["objects" ]:
75- if not "class" in object and not "parent" in object :
76- self ._map_custom_class (object , yaml_mappings )
77-
78- elif "parent" in object :
79- # Children are added to self.objects during the children->abstract parents traversal.
80- pos_constr = self ._get_pos_constr (object )
81- named_constr = self ._get_named_constr (object )
82- props = self ._get_props (object )
83- self ._traverse_parents (object , object , pos_constr , named_constr , props , abstract_objects )
84- continue
85-
8675 self ._print_obj (object )
8776 self .objects .append (self ._convert_object (object ))
8877
@@ -105,10 +94,10 @@ def _map_custom_class(self, obj, mappings):
10594 else :
10695 self .logger .warning ("No matching type found for object %s" % obj )
10796
108- def _traverse_parents (self , leaf , child , pos_constr ,
109- named_constr , props , abstract_objects ):
97+ def _convert_child_object (self , leaf , child , pos_constr ,
98+ named_constr , props ):
11099
111- parent = abstract_objects [child ["parent" ]]
100+ parent = self . abstract_objects [child ["parent" ]]
112101
113102 # At this point we only build up the lists of parameters but we don't create
114103 # the object yet because the current parent object may still have its
@@ -148,20 +137,19 @@ def _traverse_parents(self, leaf, child, pos_constr,
148137 props .append (parent_prop )
149138
150139 if "parent" in parent :
151- self ._traverse_parents (leaf , parent , pos_constr , named_constr , props , abstract_objects )
140+ # Continue traversing up the parent objects
141+ return self ._convert_child_object (leaf , parent , pos_constr , named_constr , props )
152142 else :
153143 # Now we know we can create an object out of all the accumulated values.
154-
144+
155145 # The object's class is its topmost parent's class.
156146 class_ = parent ["class" ]
157147 id , factory , lazy_init , abstract , parent , scope_ = self ._get_basic_object_data (leaf , class_ )
158148
159149 c = self ._create_object (id , factory , lazy_init , abstract , parent ,
160150 scope_ , pos_constr , named_constr , props )
161151
162- self .objects .append (c )
163-
164- return parent
152+ return c
165153
166154 def _get_pos_constr (self , object ):
167155 """ Returns a list of all positional constructor arguments of an object.
@@ -225,20 +213,25 @@ def _convert_object(self, object, prefix=""):
225213 object ["object" ] = prefix + "." + object ["object" ]
226214 else :
227215 object ["object" ] = prefix + ".<anonymous>"
228-
229- id , factory , lazy_init , abstract , parent , scope_ = self ._get_basic_object_data (object , object .get ("class" ))
230-
216+
217+ if not "class" in object and "parent" not in object :
218+ self ._map_custom_class (object , yaml_mappings )
219+
231220 pos_constr = self ._get_pos_constr (object )
232221 named_constr = self ._get_named_constr (object )
233222 props = self ._get_props (object )
223+
224+ if "parent" in object :
225+ return self ._convert_child_object (object , object , pos_constr , named_constr , props )
226+ else :
227+ id , factory , lazy_init , abstract , parent , scope_ = self ._get_basic_object_data (object , object .get ("class" ))
234228
235- return self ._create_object (id , factory , lazy_init , abstract , parent ,
236- scope_ , pos_constr , named_constr , props )
229+ return self ._create_object (id , factory , lazy_init , abstract , parent ,
230+ scope_ , pos_constr , named_constr , props )
237231
238232 def _print_obj (self , obj , level = 0 ):
239233 self .logger .debug ("%sobject = %s" % ("\t " * level , obj ["object" ]))
240- self .logger .debug ("%sobject id = %s" % ("\t " * level , obj ["object" ]))
241- self .logger .debug ("%sclass = %s" % ("\t " * (level + 1 ), obj ["class" ]))
234+ self .logger .debug ("%sclass = %s" % ("\t " * (level + 1 ), obj .get ("class" )))
242235
243236 if "scope" in obj :
244237 self .logger .debug ("%sscope = %s" % ("\t " * (level + 1 ), obj ["scope" ]))
0 commit comments