How to use 'python call superclass method' in Python

Every line of 'python call superclass method' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
33def super(cls, method):
34 """Imitate super() in a mix-in.
35
36 This method is a substitute for
37 super(MixinClass, self).overloaded_method(arg),
38 which we can't use because mix-ins appear at the end of the MRO. It should
39 be called as
40 MixinClass.super(self.overloaded_method)(arg)
41 . It works by finding the class on which MixinMeta.__init__ set
42 MixinClass.overloaded_method and calling super() on that class.
43
44 Args:
45 method: The method in the mix-in.
46 Returns:
47 The method overloaded by 'method'.
48 """
49 for supercls in type(method.__self__).__mro__:
50 # Fetch from __dict__ rather than using getattr() because we only want
51 # to consider methods defined on supercls itself (not on a parent).
52 if ("__mixin_overloads__" in supercls.__dict__ and
53 supercls.__mixin_overloads__.get(method.__name__) is cls):
54 method_cls = supercls
55 break
56 return getattr(super(method_cls, method.__self__), method.__name__)

Related snippets