beanie/odm/interfaces/inheritance.py
raw| 1 | from typing import TYPE_CHECKING, ClassVar |
| 2 | |
| 3 | if TYPE_CHECKING: |
| 4 | from beanie.odm.documents import Document |
| 5 | |
| 6 | |
| 7 | class InheritanceInterface: |
| 8 | _children: ClassVar[dict[str, type["Document"]]] |
| 9 | _parent: ClassVar["Document | None"] |
| 10 | _inheritance_inited: ClassVar[bool] |
| 11 | _class_id: ClassVar[str | None] = None |
| 12 | |
| 13 | @classmethod |
| 14 | def add_child(cls, name: str, clas: type["Document"]) -> None: |
| 15 | cls._children[name] = clas |
| 16 | if cls._parent is not None: |
| 17 | cls._parent.add_child(name, clas) |