5

When can I use super(type)? Not super(type,obj) but super(type) - with one argument.

Ella Sharakanski
  • 2,371
  • 2
  • 22
  • 43
  • 4
    Potentially interesting: https://mail.python.org/pipermail/python-3000/2007-September/010181.html (and Guido's response: https://mail.python.org/pipermail/python-3000/2007-September/010182.html) (these are from 2007 though). I also found [this](http://www.phyast.pitt.edu/~micheles/python/super.pdf), which was a bit confusing, at least to me, but might help. – Michael0x2a Nov 08 '13 at 07:08

1 Answers1

2

From my understanding, super(x) returns an "unbound" descriptor, that is, an object that knows how to get data, but has no idea where. If you assign super(x) to a class attribute and then retrieve it, the descriptor machinery cares for proper binding:

class A(object):
    def foo(self):
        print 'parent'

class B(A):
    def foo(self):
        print 'child'

B.parent = super(B)
B().foo()
B().parent.foo()

See http://www.artima.com/weblogs/viewpost.jsp?thread=236278 for details.

georg
  • 195,833
  • 46
  • 263
  • 351