jeudi 13 août 2020

How to get the class from which a method was called?

The get_calling_class function must return the class that called the A.f method:

class A:
    def f(self): return get_calling_class()

class B(A):
    def g(self): return self.f()

class C(B):
    def h(self): return self.f()

c = C()
assert c.g() == B
assert c.h() == C




Aucun commentaire:

Enregistrer un commentaire