ayon-core/openpype/pipeline/lib/attribute_definitions.py
2021-06-15 15:11:00 +02:00

42 lines
1 KiB
Python

from abc import ABCMeta, abstractmethod
import six
@six.add_metaclass(ABCMeta)
class AbtractAttrDef:
"""Abstraction of attribute definiton.
Each attribute definition must have implemented validation and
conversion method.
Attribute definition should have ability to return "default" value. That
can be based on passed data into `__init__` so is not abstracted to
attribute.
"""
@abstractmethod
def convert_value(self, value):
"""Convert value to a valid one.
Convert passed value to a valid type. Use default if value can't be
converted.
"""
pass
class BoolDef(AbtractAttrDef):
"""Boolean representation.
Args:
default(bool): Default value. Set to `False` if not defined.
"""
def __init__(self, default=None):
if default is None:
default = False
self.default = default
def convert_value(self, value):
if isinstance(value, bool):
return value
return self.default