Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of super() with not immediate parent

Tags:

python

super

Is this a legal use of super()?

class A(object):
    def method(self, arg):
        pass

class B(A):
    def method(self, arg):
        super(B,self).method(arg)

class C(B):
    def method(self, arg):
        super(B,self).method(arg)

Thank you.

like image 850
upperBound Avatar asked May 25 '11 20:05

upperBound


1 Answers

It will work, but it will probably confuse anyone trying to read your code (including you, unless you remember it specifically). Don't forget that if you want to call a method from a particular parent class, you can just do:

A.method(self, arg)
like image 104
Thomas K Avatar answered Oct 04 '22 16:10

Thomas K