When would you call super with only one argument? The only examples I can find of doing this are in the test suite for super. Playing around with it:

py> class A(object):
...     x = 'a'
...
py> class B(A):
...     x = 'b'
...
py> s = super(B)
py> s.x
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
AttributeError: 'super' object has no attribute 'x'

So I can't access class attributes with a single-argument super.

You can see that there are some interesting attributes on a super object:

py> for name in dir(s):
...    if not hasattr(object, name):
...        print name, getattr(s, name)
...
__get__ <method-wrapper object at 0x011FD050>
__self__ None
__self_class__ None
__thisclass__ <class '__main__.B'>

Looks like I can call the descriptor machinery directly to get an attribute:

py> s.__get__(B).x
'a'
py> s.__get__(B, B()).x
'a'

But this doesn't seem horribly useful. And __self__, __self_class__ and __thisclass__ are readonly, so I can't bind a super object to an instance once it's been created.

So what's the use case?

Thanks in advance,

STeVe

P.S. The context here is that I'm trying to submit a patch to clarify the docs on super a bit. But I realized that I don't actually understand its behavior with only a single argument...
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to