Hi,
Ok, now I'm really confused. What is supposed
super(<class>, <subclass of class>)
to do?
My thought was that with the following setup:
[color=blue][color=green][color=darkred]
>>> class Test(object):[/color][/color][/color]
.... def test(self):
.... return "I'm %r." % self
....[color=blue][color=green][color=darkred]
>>> class Test2(Test):[/color][/color][/color]
.... def test(self):
.... return "I'm a no one."
....[color=blue][color=green][color=darkred]
>>> super(Test, Test2).test[/color][/color][/color]
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
AttributeError: 'super' object has no attribute 'test'
So far so good, object class (the super class of Test) defines no test
method so it barfs. But
[color=blue][color=green][color=darkred]
>>> super(Test2, Test2).test[/color][/color][/color]
<bound method Test2.test of <class '__main__.Test2 '>>
Huh? shouldn't it return the *unbound* method test at class Test? And
more:
[color=blue][color=green][color=darkred]
>>> a = Test2()
>>> super(Test2, Test2).test(a)[/color][/color][/color]
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: test() takes exactly 1 argument (2 given)[color=blue][color=green][color=darkred]
>>> super(Test2, Test2).test()[/color][/color][/color]
"I'm <class '__main__.Test2 '>."[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
A bug? Or my perceptions on what super(<class>, <subclass of class>)
should do are totally mixed up?
With my best regards,
G. Rodrigues
Ok, now I'm really confused. What is supposed
super(<class>, <subclass of class>)
to do?
My thought was that with the following setup:
[color=blue][color=green][color=darkred]
>>> class Test(object):[/color][/color][/color]
.... def test(self):
.... return "I'm %r." % self
....[color=blue][color=green][color=darkred]
>>> class Test2(Test):[/color][/color][/color]
.... def test(self):
.... return "I'm a no one."
....[color=blue][color=green][color=darkred]
>>> super(Test, Test2).test[/color][/color][/color]
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
AttributeError: 'super' object has no attribute 'test'
So far so good, object class (the super class of Test) defines no test
method so it barfs. But
[color=blue][color=green][color=darkred]
>>> super(Test2, Test2).test[/color][/color][/color]
<bound method Test2.test of <class '__main__.Test2 '>>
Huh? shouldn't it return the *unbound* method test at class Test? And
more:
[color=blue][color=green][color=darkred]
>>> a = Test2()
>>> super(Test2, Test2).test(a)[/color][/color][/color]
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: test() takes exactly 1 argument (2 given)[color=blue][color=green][color=darkred]
>>> super(Test2, Test2).test()[/color][/color][/color]
"I'm <class '__main__.Test2 '>."[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
A bug? Or my perceptions on what super(<class>, <subclass of class>)
should do are totally mixed up?
With my best regards,
G. Rodrigues
Comment