[Python-3000] let's get rid of unbound super methods

Michele Simionato michele.simionato at gmail.com
Sat Sep 1 10:33:32 CEST 2007


So Python 3000a1 is out! Kudos to everybody involved!
You did an incredible amount of work in a relatively short time! :-)

Having said that, let me go to the point. This morning I downloaded
the tarball and compiled everything without issues, then I
started playing around. One of the first thing I looked at was the new
super, since it is a matter that made me scratch my head a lot in the
past. Basically I am happy with the implementation, especially about
the new magic name __class__ inside the methods which is something I
always wanted. So I am not here to ask for new features. I am actually
here to ask for less features: specifically, I would like the unbound
syntax for super to be removed. I am talking about this:

>>> help(super)
Help on class super in module __builtin__:

class super(object)
 |  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)


The single argument syntax 'super(type)' is what I call the unbound syntax.
I would like 'super(type)' to be removed from the valid signatures.
AFAIK, the only use case for it was the implementation of the autosuper
recipe in Guido's new style classes essay. That use case has disappeared
nowadays, and I cannot think of other situations where may want to use
that feature (you may think differently, if so, please speak).
The other reason why I would like it to be removed (apart from the fact
that it looks unneeded to me) is that is very difficult to explain to
beginners. For instance in the past I lectured on Python, and in order
to explain why unbound super objects can be useful I gave this example,
which is basically Guido's autosuper recipe implemented by hand:

class B(object):
  def __repr__(self):
      return '<instance of %s>' % self.__class__.__name__
  #@classmethod
  def cmeth(self):
      print("B.meth called from %s" % self)

class C(B):
  #@classmethod
  def cmeth(self):
      print("C.meth called from %s" % self)
      self.__super.cmeth()

C._C__super = super(C)

c = C()

c.cmeth()

Here everything works because the unbound super object is a descriptor
and self.__super calls super(C).__get__(self, C) which corresponds
to the bound method super(C, self) which is able to dispatch to .cmeth.
However, if you uncomment the classmethod decorator, self.__super (where
self is now the class C) will just return the unbound super object super(C)
which is unable to dispatch to .cmeth. Now, try to explain that to a beginner!
We can leave just as well without unbound super methods, so let's take
the occasion of Python3k to remove this glitch.


                           Michele Simionato


More information about the Python-3000 mailing list