mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-02 00:44:52 +01:00
implemented meta class AbstractAttrDefMeta for validation of key attribute
This commit is contained in:
parent
55d9bc1081
commit
aa9d947614
1 changed files with 15 additions and 1 deletions
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue