@@ -3859,6 +3859,7 @@ Add(1, 0)=1
38593859[case testInheritedDunderNew]
38603860from __future__ import annotations
38613861from mypy_extensions import mypyc_attr
3862+ from testutil import assertRaises
38623863from typing_extensions import Self
38633864
38643865from m import interpreted_subclass
@@ -3875,19 +3876,32 @@ class Base:
38753876 def __init__(self, val: int) -> None:
38763877 self.init_val = val
38773878
3879+ def method(self) -> int:
3880+ raise NotImplementedError
3881+
38783882class Sub(Base):
3883+
38793884 def __new__(cls, val: int) -> Self:
38803885 return super().__new__(cls, val + 1)
38813886
38823887 def __init__(self, val: int) -> None:
38833888 super().__init__(val)
38843889 self.init_val = self.init_val * 2
38853890
3891+ def method(self) -> int:
3892+ return 0
3893+
38863894class SubWithoutNew(Base):
3895+ sub_only_str = ""
3896+ sub_only_int: int
3897+
38873898 def __init__(self, val: int) -> None:
38883899 super().__init__(val)
38893900 self.init_val = self.init_val * 2
38903901
3902+ def method(self) -> int:
3903+ return 1
3904+
38913905class BaseWithoutInterpretedSubclasses:
38923906 val: int
38933907
@@ -3899,6 +3913,9 @@ class BaseWithoutInterpretedSubclasses:
38993913 def __init__(self, val: int) -> None:
39003914 self.init_val = val
39013915
3916+ def method(self) -> int:
3917+ raise NotImplementedError
3918+
39023919class SubNoInterpreted(BaseWithoutInterpretedSubclasses):
39033920 def __new__(cls, val: int) -> Self:
39043921 return super().__new__(cls, val + 1)
@@ -3907,55 +3924,77 @@ class SubNoInterpreted(BaseWithoutInterpretedSubclasses):
39073924 super().__init__(val)
39083925 self.init_val = self.init_val * 2
39093926
3927+ def method(self) -> int:
3928+ return 0
3929+
39103930class SubNoInterpretedWithoutNew(BaseWithoutInterpretedSubclasses):
39113931 def __init__(self, val: int) -> None:
39123932 super().__init__(val)
39133933 self.init_val = self.init_val * 2
39143934
3935+ def method(self) -> int:
3936+ return 1
3937+
39153938def test_inherited_dunder_new() -> None:
39163939 b = Base(42)
39173940 assert type(b) == Base
39183941 assert b.val == 43
39193942 assert b.init_val == 42
3943+ with assertRaises(NotImplementedError):
3944+ b.method()
39203945
39213946 s = Sub(42)
39223947 assert type(s) == Sub
39233948 assert s.val == 44
39243949 assert s.init_val == 84
3950+ assert s.method() == 0
39253951
39263952 s2 = SubWithoutNew(42)
39273953 assert type(s2) == SubWithoutNew
39283954 assert s2.val == 43
39293955 assert s2.init_val == 84
3956+ assert s2.method() == 1
3957+ assert s2.sub_only_str == ""
3958+ with assertRaises(AttributeError):
3959+ s2.sub_only_int
3960+ s2.sub_only_int = 11
3961+ assert s2.sub_only_int == 11
39303962
39313963def test_inherited_dunder_new_without_interpreted_subclasses() -> None:
39323964 b = BaseWithoutInterpretedSubclasses(42)
39333965 assert type(b) == BaseWithoutInterpretedSubclasses
39343966 assert b.val == 43
39353967 assert b.init_val == 42
3968+ with assertRaises(NotImplementedError):
3969+ b.method()
39363970
39373971 s = SubNoInterpreted(42)
39383972 assert type(s) == SubNoInterpreted
39393973 assert s.val == 44
39403974 assert s.init_val == 84
3975+ assert s.method() == 0
39413976
39423977 s2 = SubNoInterpretedWithoutNew(42)
39433978 assert type(s2) == SubNoInterpretedWithoutNew
39443979 assert s2.val == 43
39453980 assert s2.init_val == 84
3981+ assert s2.method() == 1
39463982
39473983def test_interpreted_subclass() -> None:
39483984 interpreted_subclass(Base)
39493985
39503986[file m.py]
39513987from __future__ import annotations
3988+ from testutil import assertRaises
39523989from typing_extensions import Self
39533990
39543991def interpreted_subclass(base) -> None:
39553992 b = base(42)
39563993 assert type(b) == base
39573994 assert b.val == 43
39583995 assert b.init_val == 42
3996+ with assertRaises(NotImplementedError):
3997+ b.method()
39593998
39603999 class InterpretedSub(base):
39614000 def __new__(cls, val: int) -> Self:
@@ -3965,20 +4004,36 @@ def interpreted_subclass(base) -> None:
39654004 super().__init__(val)
39664005 self.init_val : int = self.init_val * 2
39674006
4007+ def method(self) -> int:
4008+ return 3
4009+
39684010 s = InterpretedSub(42)
39694011 assert type(s) == InterpretedSub
39704012 assert s.val == 44
39714013 assert s.init_val == 84
4014+ assert s.method() == 3
39724015
39734016 class InterpretedSubWithoutNew(base):
4017+ sub_only_str = ""
4018+ sub_only_int: int
4019+
39744020 def __init__(self, val: int) -> None:
39754021 super().__init__(val)
39764022 self.init_val : int = self.init_val * 2
39774023
4024+ def method(self) -> int:
4025+ return 4
4026+
39784027 s2 = InterpretedSubWithoutNew(42)
39794028 assert type(s2) == InterpretedSubWithoutNew
39804029 assert s2.val == 43
39814030 assert s2.init_val == 84
4031+ assert s2.method() == 4
4032+ assert s2.sub_only_str == ""
4033+ with assertRaises(AttributeError):
4034+ s2.sub_only_int
4035+ s2.sub_only_int = 11
4036+ assert s2.sub_only_int == 11
39824037
39834038[typing fixtures/typing-full.pyi]
39844039
0 commit comments