Skip to content

Commit 4b3b673

Browse files
authored
added default_value fallback to serializable_field property (AcademySoftwareFoundation#1658)
Signed-off-by: Tim Lehr <[email protected]>
1 parent e8228a0 commit 4b3b673

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/py-opentimelineio/opentimelineio/core/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def wrapped_update(data):
240240
return decorator_func
241241

242242

243-
def serializable_field(name, required_type=None, doc=None):
243+
def serializable_field(name, required_type=None, doc=None, default_value=None):
244244
"""
245245
Convenience function for adding attributes to child classes of
246246
:class:`~SerializableObject` in such a way that they will be serialized/deserialized
@@ -274,13 +274,14 @@ class Foo(SerializableObject):
274274
:param str name: name of the field to add
275275
:param type required_type: type required for the field
276276
:param str doc: field documentation
277+
:param Any default_value: default value to return if no field value is set yet
277278
278279
:return: property object
279280
:rtype: :py:class:`property`
280281
"""
281282

282283
def getter(self):
283-
return self._dynamic_fields[name]
284+
return self._dynamic_fields.get(name, default_value)
284285

285286
def setter(self, val):
286287
# always allow None values regardless of value of required_type

0 commit comments

Comments
 (0)