@@ -114,8 +114,11 @@ def get_sections(self, section_list):
114
114
section_dict [attr ] = sections
115
115
else :
116
116
tag = getattr (section , attr )
117
-
118
- if tag :
117
+ # Tuples have to be serialized as lists to avoid
118
+ # nasty python code annotations when writing to yaml.
119
+ if tag and isinstance (tag , tuple ):
120
+ section_dict [i ] = list (tag )
121
+ elif tag :
119
122
# Always use the arguments key attribute name when saving
120
123
section_dict [i ] = tag
121
124
@@ -143,6 +146,8 @@ def get_properties(props_list):
143
146
144
147
if hasattr (prop , attr ):
145
148
tag = getattr (prop , attr )
149
+ # Tuples have to be serialized as lists to avoid
150
+ # nasty python code annotations when writing to yaml.
146
151
if isinstance (tag , tuple ):
147
152
prop_dict [attr ] = list (tag )
148
153
elif (tag == []) or tag : # Even if 'values' is empty, allow '[]'
@@ -266,8 +271,14 @@ def parse_sections(self, section_list):
266
271
elif attr == 'sections' :
267
272
children_secs = self .parse_sections (section ['sections' ])
268
273
elif attr :
274
+ # Tuples had to be serialized as lists to support the yaml format.
275
+ # Now convert cardinality lists back to tuples.
276
+ content = section [attr ]
277
+ if attr .endswith ("_cardinality" ):
278
+ content = parse_cardinality (content )
279
+
269
280
# Make sure to always use the correct odml format attribute name
270
- sec_attrs [odmlfmt .Section .map (attr )] = section [ attr ]
281
+ sec_attrs [odmlfmt .Section .map (attr )] = content
271
282
272
283
sec = odmlfmt .Section .create (** sec_attrs )
273
284
for prop in sec_props :
@@ -297,6 +308,8 @@ def parse_properties(self, props_list):
297
308
attr = self .is_valid_attribute (i , odmlfmt .Property )
298
309
if attr :
299
310
content = _property [attr ]
311
+ # Tuples had to be serialized as lists to support the yaml format.
312
+ # Now convert cardinality lists back to tuples.
300
313
if attr .endswith ("_cardinality" ):
301
314
content = parse_cardinality (content )
302
315
0 commit comments