super question

Gonçalo Rodrigues op73418 at
Mon Sep 1 12:40:31 CEST 2003


Ok, now I'm really confused. What is supposed

super(<class>, <subclass of class>)

to do?

My thought was that with the following setup:

>>> class Test(object):
... 	def test(self):
... 		return "I'm %r." % self
>>> class Test2(Test):
... 	def test(self):
... 		return "I'm a no one."
>>> super(Test, Test2).test
Traceback (most recent call last):
  File "<interactive 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

>>> super(Test2, Test2).test
<bound method Test2.test of <class '__main__.Test2'>>

Huh? shouldn't it return the *unbound* method test at class Test? And

>>> a = Test2()
>>> super(Test2, Test2).test(a)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: test() takes exactly 1 argument (2 given)
>>> super(Test2, Test2).test()
"I'm <class '__main__.Test2'>."

A bug? Or my perceptions on what super(<class>, <subclass of class>)
should do are totally mixed up?

With my best regards,
G. Rodrigues

More information about the Python-list mailing list