Skip to content

Commit

Permalink
added default_value fallback to serializable_field property (Acad…
Browse files Browse the repository at this point in the history
  • Loading branch information
timlehr authored Apr 18, 2024
1 parent e8228a0 commit 4b3b673
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/py-opentimelineio/opentimelineio/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def wrapped_update(data):
return decorator_func


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

def getter(self):
return self._dynamic_fields[name]
return self._dynamic_fields.get(name, default_value)

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

0 comments on commit 4b3b673

Please sign in to comment.