summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorCarl Meyer <carl@oddbird.net>2023-07-24 21:13:17 (GMT)
committerGitHub <noreply@github.com>2023-07-24 21:13:17 (GMT)
commit5fd028b677ae1dd20a60fc2f43d4380b809d70f0 (patch)
tree5812a87b8c1792e73f98712500cf17bd9848c1e9 /Lib/test
parent3923639a77656915c3499b0283a45da727308f2a (diff)
downloadcpython-5fd028b677ae1dd20a60fc2f43d4380b809d70f0.zip
cpython-5fd028b677ae1dd20a60fc2f43d4380b809d70f0.tar.gz
cpython-5fd028b677ae1dd20a60fc2f43d4380b809d70f0.tar.bz2
[3.12] gh-106917: fix super classmethod calls to non-classmethods (GH-106977). (#107204)
(cherry picked from commit e5d5522612e03af3941db1d270bf6caebf330b8a)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_super.py46
1 files changed, 44 insertions, 2 deletions
diff --git a/Lib/test/test_super.py b/Lib/test/test_super.py
index 664cf70..43162c5 100644
--- a/Lib/test/test_super.py
+++ b/Lib/test/test_super.py
@@ -5,6 +5,9 @@ from unittest.mock import patch
from test import shadowed_super
+ADAPTIVE_WARMUP_DELAY = 2
+
+
class A:
def f(self):
return 'A'
@@ -419,8 +422,47 @@ class TestSuper(unittest.TestCase):
super(MyType, type(mytype)).__setattr__(mytype, "bar", 1)
self.assertEqual(mytype.bar, 1)
- test("foo1")
- test("foo2")
+ for _ in range(ADAPTIVE_WARMUP_DELAY):
+ test("foo1")
+
+ def test_reassigned_new(self):
+ class A:
+ def __new__(cls):
+ pass
+
+ def __init_subclass__(cls):
+ if "__new__" not in cls.__dict__:
+ cls.__new__ = cls.__new__
+
+ class B(A):
+ pass
+
+ class C(B):
+ def __new__(cls):
+ return super().__new__(cls)
+
+ for _ in range(ADAPTIVE_WARMUP_DELAY):
+ C()
+
+ def test_mixed_staticmethod_hierarchy(self):
+ # This test is just a desugared version of `test_reassigned_new`
+ class A:
+ @staticmethod
+ def some(cls, *args, **kwargs):
+ self.assertFalse(args)
+ self.assertFalse(kwargs)
+
+ class B(A):
+ def some(cls, *args, **kwargs):
+ return super().some(cls, *args, **kwargs)
+
+ class C(B):
+ @staticmethod
+ def some(cls):
+ return super().some(cls)
+
+ for _ in range(ADAPTIVE_WARMUP_DELAY):
+ C.some(C)
if __name__ == "__main__":