Python super() raises TypeError Python super() raises TypeError python python

Python super() raises TypeError


The reason is that super() only operates on new-style classes, which in the 2.x series means extending from object:

>>> class X(object):        def a(self):            print 'a'>>> class Y(X):        def a(self):            super(Y, self).a()            print 'b'>>> c = Y()>>> c.a()ab


In addition, don't use super() unless you have to. It's not the general-purpose "right thing" to do with new-style classes that you might suspect.

There are times when you're expecting multiple inheritance and you might possibly want it, but until you know the hairy details of the MRO, best leave it alone and stick to:

 X.a(self)


In case none of the above answers mentioned it clearly. Your parent class needs to inherit from "object", which would essentially turn it into a new style class.

# python 3.x:class ClassName(object): # This is a new style class    passclass ClassName: # This is also a new style class ( implicit inheritance from object )    pass# Python 2.x:class ClassName(object): # This is a new style class    passclass ClassName:         # This is a old style class    pass