Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lmignon committed Oct 3, 2023
1 parent bff82c8 commit 4d02139
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/extendable/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
class ExtendableClassDef:
name: str
base_names: List[str]
original_base_names: List[str]
namespace: Dict[str, Any]
original_name: str
others_bases: List[Any]
Expand All @@ -44,7 +45,8 @@ def __init__(
self.name = namespace["__xreg_name__"]
self.original_name = original_name
self.others_bases = bases
self.base_names = namespace["__xreg_base_names__"] or []
self.base_names = namespace["__xreg_base_names__"].copy() or []
self.original_base_names = self.base_names.copy()
self.hierarchy = [self]
self.metaclass = metaclass
self.kwargs = kwargs
Expand Down
2 changes: 1 addition & 1 deletion src/extendable/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def build_extendable_class(
f"Pydnatic class '{name}' extends an non-existing "
f"extendable class '{base_name}'."
)
else:
elif base_name in cls_def.original_base_names:
parent_class = self[base_name]
bases.add(parent_class)
for other_base in class_def.others_bases:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,35 @@ class MyExt(metaclass=MyMeta):
assert MyMeta._is_extendable(MyExt)


def test_mixin_inheritance(test_registry):
class BaseMixin(metaclass=ExtendableMeta):
def test(self):
return "base"

class MixinA(BaseMixin):
def test_a(self):
return "A"

class MixinB(BaseMixin):
def test_b(self):
return "B"

class ExtendedB(MixinB, extends=True):
def test_b(self):
res = super().test_b()
return res + " extended"

class Mixin(MixinA, MixinB, extends=MixinB):
pass

test_registry.init_registry()

obj = Mixin()
assert obj.test() == "base"
assert obj.test_a() == "A"
assert obj.test_b() == "B extended"


def test_issubclass_multi_level(test_registry):
class A(metaclass=ExtendableMeta):
pass
Expand Down

0 comments on commit 4d02139

Please sign in to comment.