super() Raises `TypeError: must be type, not classobj`

If you try to use Python’s super method, and receive {{{TypeError: must be type, not classobj}}}, your parent class is an old style class (and does not in some way inherit from object). The below code is an illustration of the issue:
{{{ lang=python lines=1
class class_A:
def __init__( self ):
print ‘Class A’

class class_B( class_A ):
def __init__( self ):
print ‘Class B’
super( class_B, self ).__init__()

class_B()

# Running the above will raise `TypeError: must be type, not classobj`
}}}
The Fixed Code:
{{{ lang=python lines=1
class class_A( object ): #< Note the inheritance of `object`. def __init__( self ): print 'Class A' class class_B( class_A ): def __init__( self ): print 'Class B' super( class_B, self ).__init__() class_B() # Running the above will no longer raise `TypeError: must be type, not classobj` }}}


Posted

in

by

Tags:

Comments

3 responses to “super() Raises `TypeError: must be type, not classobj`”

  1. jay Avatar
    jay

    thanks Las.. it helped me a lot.

  2. Raz Avatar
    Raz

    Thanks! Helped me too :)

  3. Ram Mourya Avatar
    Ram Mourya

    Thanks alot

Leave a Reply

Your email address will not be published. Required fields are marked *