Fix Python – Why is Python 3.x’s super() magic?

In Python 3.x, super() can be called without arguments:
class A(object):
def x(self):
print(“Hey now”)

class B(A):
def x(self):

>>> B().x()
Hey now

In order to make this work, some compile-time magic is performed, one consequence of which is that the following code (which rebinds super to super_) fails:

Fix Python – super() fails with error: TypeError “argument 1 must be type, not classobj” when parent does not inherit from object

I get some error that I can’t figure out. Any clue what is wrong with my sample code?
class B:
def meth(self, arg):
print arg

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

print C().meth(1)

I got the sample test code from help of ‘super’ built-in method.
Here is the error:
Traceback (most recent call last):

Fix Python – Calling parent class __init__ with multiple inheritance, what’s the right way?

Say I have a multiple inheritance scenario:
class A(object):
# code for A here

class B(object):
# code for B here

class C(A, B):
def __init__(self):
# What’s the right code to write here to ensure
# A.__init__ and B.__init__ get called?

There’s two typical approaches to writing C’s __init__:

(old-style) ParentClass….

Fix Python – super() raises “TypeError: must be type, not classobj” for new-style class

The following use of super() raises a TypeError: why?
>>> from HTMLParser import HTMLParser
>>> class TextParser(HTMLParser):
… def __init__(self):
… super(TextParser, self).__init__()
… self.all_data = []

>>> TextParser()
TypeError: must be type, not classobj

There is a similar question on StackOverf….

Fix Python – What does ‘super’ do in Python? – difference between super().__init__() and explicit superclass __init__()

What’s the difference between:
class Child(SomeBaseClass):
def __init__(self):
super(Child, self).__init__()

class Child(SomeBaseClass):
def __init__(self):

I’ve seen super being used quite a lot in classes with only single inheritance. I can see why you’d use it in multiple inheritance b….