Using metaclasses to make super more beatiful

Gerrit Holl gerrit at
Thu Jun 5 18:50:14 CEST 2003


as demonstrated by Guido's paper[0], a relatively simple metaclass
can make the use of super a lot more beatiful:

 97 >>> class autosuper(type):
 97 ...  def __init__(cls, name, bases, dict):
 97 ...   super(autosuper, cls).__init__(name, bases, dict)
 97 ...   setattr(cls, "super", super(cls))
 97 ...
 98 >>> class A:
 98 ...  __metaclass__ = autosuper
 98 ...  def f(self): return "A"
 98 ...
100 >>> class B(A):
100 ...  def f(self):
100 ...   return self.super.f()
100 ...
101 >>> B()
<__main__.B object at 0x403b3c6c>
102 >>> B().f()

Why doesn't type include the behaviour of autosuper by default,
so that each class can use self.super or self.__super__ so that
using super is easier?

And, is it convention not to use Capitalization for metaclasses?
In three examples, Guido doensn't do it in his paper[0]!



39. He may, however, assign a field, garden, or house which he has
bought, and holds as property, to his wife or daughter or give it for
        -- 1780 BC, Hammurabi, Code of Law
Asperger Syndroom - een persoonlijke benadering:
Het zijn tijden om je zelf met politiek te bemoeien:

More information about the Python-list mailing list