super(obj)?

Alex Martelli aleax at aleax.it
Mon Feb 18 11:30:05 EST 2002


Gustavo Niemeyer wrote:

> Hello everyone!
> 
> AFAICS, this seems to be the most useful version of super:
> 
> super(obj.__class__, obj)

I don't get it.  Why would this be "most useful"?  E.g.:

class X(object):
  def foo(self):
    print 'X.foo'
    try: supermethod = super(self.__class__, self).foo
    except: pass
    else: supermethod()

class Y(X):
  def foo(self):
    print 'Y.foo'
    try: supermethod = super(self.__class__, self).foo
    except: pass
    else: supermethod()

    
This systematically raises 'maximum recursion depth
exceeded'.  More generally, if each method restarts
the search-for-super 'from the root' (self.__class__),
how is the search EVER going to terminate...?  Just
by exceeding recursion limits, no?

I guess I must be missing something, but really can't
see what.  Explain please?  Thanks!


Alex




More information about the Python-list mailing list