Created
May 18, 2022 12:12
-
-
Save travishen/5273057cc920974f65fc996ae14359ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EntityMeta(type): | |
"""Metaclass for business entities with validated fields""" | |
def __init__(cls, name, bases, attr_dict): | |
# handover to type.__init__ | |
super().__init__(name, bases, attr_dict) | |
for key, attr in attr_dict.items(): | |
if isinstance(attr, Validated): | |
type_name = type(attr).__name__ | |
attr.storage_name = f'_{type_name}#{key}' | |
class Entity(metaclass=EntityMeta): | |
"""Shortcut class for direct inheritance.""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment