From aa9d94761421cf80d8e0a2148c11dff140c235c3 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 16 Jun 2021 11:33:08 +0200 Subject: [PATCH] implemented meta class AbstractAttrDefMeta for validation of key attribute --- openpype/pipeline/lib/attribute_definitions.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/openpype/pipeline/lib/attribute_definitions.py b/openpype/pipeline/lib/attribute_definitions.py index eac236e894..e14bc6d8f3 100644 --- a/openpype/pipeline/lib/attribute_definitions.py +++ b/openpype/pipeline/lib/attribute_definitions.py @@ -4,7 +4,21 @@ from abc import ABCMeta, abstractmethod import six -@six.add_metaclass(ABCMeta) +class AbstractAttrDefMeta(ABCMeta): + """Meta class to validate existence of 'key' attribute. + + Each object of `AbtractAttrDef` mus have defined 'key' attribute. + """ + def __call__(self, *args, **kwargs): + obj = super(AbstractAttrDefMeta, self).__call__(*args, **kwargs) + if not hasattr(obj, "key"): + raise TypeError("<{}> must have defined 'key' attribute.".format( + obj.__class__.__name__ + )) + return obj + + +@six.add_metaclass(AbstractAttrDefMeta) class AbtractAttrDef: """Abstraction of attribute definiton.