Python: Why can't I use `super` on a class?
- by cool-RR
Why can't I use super to get a method of a class's superclass?
Example:
Python 3.1.3
>>> class A(object):
... def my_method(self): pass
>>> class B(A):
... def my_method(self): pass
>>> super(B).my_method
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
super(B).my_method
AttributeError: 'super' object has no attribute 'my_method'
(Of course this is a trivial case where I could just do A.my_method, but I needed this for a case of diamond-inheritance.)
According to super's documentation, it seems like what I want should be possible. This is super's documentation: (Emphasis mine)
super() - same as super(__class__,
<first argument>)
super(type) - unbound super object
super(type, obj) - bound super
object; requires isinstance(obj, type)
super(type, type2) - bound super
object; requires issubclass(type2,
type)
[non-relevant examples redacted]