mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 13:52:15 +01:00
added methods for conversion to valid value types
This commit is contained in:
parent
95d8f7fb31
commit
af1c18db1f
1 changed files with 30 additions and 0 deletions
|
|
@ -324,6 +324,36 @@ class BaseItemEntity(BaseEntity):
|
|||
|
||||
raise InvalidValueType(self.valid_value_types, type(value), self.path)
|
||||
|
||||
def _convert_to_valid_type(self, value):
|
||||
"""Private method of entity to convert value.
|
||||
|
||||
NOTE: Method is not abstract as more entities won't have implemented
|
||||
logic inside.
|
||||
|
||||
Must return NOT_SET if can't convert the value.
|
||||
"""
|
||||
return NOT_SET
|
||||
|
||||
def convert_to_valid_type(self, value):
|
||||
"""Check value type with possibility of conversion to valid.
|
||||
|
||||
If entered value has right type than is returned as it is. otherwise
|
||||
is used privete method of entity to try convert.
|
||||
|
||||
Raises:
|
||||
InvalidValueType: If value's type is not valid by entity's
|
||||
definition and can't be converted by entity logic.
|
||||
"""
|
||||
#
|
||||
if self.is_value_valid_type(value):
|
||||
return value
|
||||
|
||||
new_value = self._convert_to_valid_type(value)
|
||||
if new_value is not NOT_SET and self.is_value_valid_type(new_value):
|
||||
return new_value
|
||||
|
||||
raise InvalidValueType(self.valid_value_types, type(value), self.path)
|
||||
|
||||
# TODO convert to private method
|
||||
def _check_update_value(self, value, value_source):
|
||||
"""Validation of value on update methods.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue