6

I did this code:

class Square(Quad):
 def __init__(self, linesValue):
 """Calls the builder in quad (same)"""
 super(Square, self).__init__(linesValue)

then It said I have to send type as first arg, so I did this:

class Square(Quad):
 def __init__(self, linesValue):
 """Calls the builder in quad (same)"""
 super(type(Square), self).__init__(linesValue)

then it said obj must be instance of subinstance of class, and as you can see Square(Quad) it is.

asked Nov 17, 2013 at 18:04
2
  • Not sure it will solve your issue, but the call to super should be in __init__ (it's currently at the scope of the function definition). Commented Nov 17, 2013 at 18:08
  • 1
    How did you define Quad? It should inherit from object. Commented Nov 17, 2013 at 18:09

2 Answers 2

7

Considering your indentation is correct then in Python2 a class should inherit from object, otherwise it would be considered as a classic class. And you can't use super on a classic class.

So, if Quad is defined like this, then it is wrong:

class Quad:
 def __init__(self, x):
 pass

And instantiating Square will raise error like this:

>>> Square(12)
 ...
 super(Square, self).__init__(linesValue)
TypeError: must be type, not classobj

Change Quad to inherit from object:

class Quad(object):
 def __init__(self, x):
 print x

Demo:

>>> Square(12)
12
<__main__.Square object at 0x93e286c>
answered Nov 17, 2013 at 18:13
Sign up to request clarification or add additional context in comments.

3 Comments

There are lot of ways to get error, and OP seems to used all of them consecutively
@latheiere Unless OP provides exact code and traceback all we can do is guess. ;-)
Thank you! I didn't know that I HAS to be from object
2

You have bad indentation, and so your super is outside of __init__. Compare:

>>> class Square(Quad):
... def __init__(self, linesValue):
... """Calls the builder in quad (same)"""
... super(Square, self).__init__(linesValue)
...
>>>

and

>>> class Square(Quad):
... def __init__(self, linesValue):
... """Calls the builder in quad (same)"""
... super(type(Square), self).__init__(linesValue)
...
Traceback (most recent call last):
 ...
TypeError: super(type, obj): obj must be an instance or subtype of type

and

>>> class Square(Quad):
... def __init__(self, linesValue):
... """Calls the builder in quad (same)"""
... super(Square, self).__init__(linesValue)
...
Traceback (most recent call last):
 ...
TypeError: super(type, obj): obj must be an instance or subtype of type
answered Nov 17, 2013 at 18:09

2 Comments

There are lot of ways to get error, and OP seems to used all of them consecutively
And the super outside the init was a problem in stackoverflow's topic maker, fixed it

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.