py/runtime: Fix self arg passed to classmethod when accessed via super.

Thanks to @AJMansfield for the original test case.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2024-07-24 17:17:39 +10:00
parent 07bf3179f6
commit 233f5ce661
2 changed files with 35 additions and 0 deletions

View File

@@ -35,3 +35,34 @@ class B(A):
B.bar() # class calling classmethod
B().bar() # instance calling classmethod
B().baz() # instance calling normal method
# super inside a classmethod
# ensure the argument of the super method that is called is the child type
class C:
@classmethod
def f(cls):
print("C.f", cls.__name__) # cls should be D
@classmethod
def g(cls):
print("C.g", cls.__name__) # cls should be D
class D(C):
@classmethod
def f(cls):
print("D.f", cls.__name__)
super().f()
@classmethod
def g(cls):
print("D.g", cls.__name__)
super(D, cls).g()
D.f()
D.g()
D().f()
D().g()