From b95a13720df59f0ad327e886f152975fe3ee9f12 Mon Sep 17 00:00:00 2001 From: David C Ellis Date: Thu, 27 Jun 2024 10:56:56 +0100 Subject: [PATCH] Test for super() fixes --- tests/test_core.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_core.py b/tests/test_core.py index dc6a9de..46a1a63 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -8,6 +8,7 @@ builder, default_methods, + eq_maker, get_fields, get_flags, get_methods, @@ -527,3 +528,33 @@ class SigClass: __slots__ = SlotFields(x=42) assert str(inspect.signature(SigClass)) == "(x=42)" + + +def test_subclass_method_not_overwritten(): + @slotclass + class X: + __slots__ = SlotFields(x=Field()) + + class Y(X): + def __init__(self, x, y): + self.y = y + super().__init__(x=x) + + y_init_func = Y.__init__ + + assert X.__dict__["__eq__"] is eq_maker + + y_inst = Y(0, 1) + + # super().__init__ method generated correctly + assert y_init_func is Y.__init__ + assert X.__dict__["__init__"] is not init_maker + assert (y_inst.x, y_inst.y) == (0, 1) + + # Would fail previously as __init__ would be overwritten + y_inst_2 = Y(0, 2) + + assert y_inst == y_inst_2 + + assert X.__dict__["__eq__"] is not eq_maker + assert "__eq__" not in Y.__dict__