@@ -276,15 +276,20 @@ def create_struct_from_obj(self, ob):
276276 struct [childname ] = []
277277
278278 # attributes
279- for i , attr in enumerate (ob ._all_attrs ):
279+ all_attrs = list (ob ._all_attrs )
280+ if hasattr (ob , 'annotations' ):
281+ all_attrs .append (('annotations' , type (ob .annotations )))
282+
283+ for i , attr in enumerate (all_attrs ):
280284 attrname , attrtype = attr [0 ], attr [1 ]
281285
282286 # ~ if attrname =='':
283287 # ~ struct['array'] = ob.magnitude
284288 # ~ struct['units'] = ob.dimensionality.string
285289 # ~ continue
286290
287- if (hasattr (ob , '_quantity_attr' ) and ob ._quantity_attr == attrname ):
291+ if (hasattr (ob , '_quantity_attr' ) and
292+ ob ._quantity_attr == attrname ):
288293 struct [attrname ] = ob .magnitude
289294 struct [attrname + '_units' ] = ob .dimensionality .string
290295 continue
@@ -308,7 +313,7 @@ def create_struct_from_obj(self, ob):
308313
309314 def create_ob_from_struct (self , struct , classname ):
310315 cl = class_by_name [classname ]
311- # check if hinerits Quantity
316+ # check if inherits Quantity
312317 # ~ is_quantity = False
313318 # ~ for attr in cl._necessary_attrs:
314319 # ~ if attr[0] == '' and attr[1] == pq.Quantity:
@@ -372,13 +377,16 @@ def create_ob_from_struct(self, struct, classname):
372377 if attrname .endswith ('_units' ) or attrname == 'units' :
373378 # linked with another field
374379 continue
375- if (hasattr (cl , '_quantity_attr' ) and cl ._quantity_attr == attrname ):
380+
381+ if hasattr (cl , '_quantity_attr' ) and cl ._quantity_attr == attrname :
376382 continue
377383
378384 item = getattr (struct , attrname )
379385
380- attributes = cl ._necessary_attrs + cl ._recommended_attrs
381- dict_attributes = {a [0 ]: a [1 :] for a in attributes }
386+ attributes = cl ._necessary_attrs + cl ._recommended_attrs \
387+ + (('annotations' , dict ),)
388+ dict_attributes = dict ([(a [0 ], a [1 :]) for a in attributes ])
389+
382390 if attrname in dict_attributes :
383391 attrtype = dict_attributes [attrname ][0 ]
384392 if attrtype == datetime :
@@ -398,6 +406,9 @@ def create_ob_from_struct(self, struct, classname):
398406 item = pq .Quantity (item , units )
399407 else :
400408 item = pq .Quantity (item , units )
409+ elif attrtype == dict :
410+ # FIXME: works but doesn't convert nested struct to dict
411+ item = {fn : getattr (item , fn ) for fn in item ._fieldnames }
401412 else :
402413 item = attrtype (item )
403414
0 commit comments