Using metaclasses to make super more beatiful

Gerrit Holl gerrit at nl.linux.org
Thu Jun 5 21:10:05 CEST 2003


Just schreef op donderdag  5 juni om 20:08:10 +0000:
>  Gerrit Holl <gerrit at nl.linux.org> wrote:
> >  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()
> > 'A'

> Tip: create a class C, derived from B, then call f() on an instance of 
> C, and see what happens <wink>.

RuntimeError: maximum recursion depth exceeded

Hmm, I thought I understood it but I apparantly don't, since I don't
see why this happens... 

I must read some more documentation, I think.

yours,
Gerrit.

-- 
104. If a merchant give an agent corn, wool, oil, or any other goods to
transport, the agent shall give a receipt for the amount, and compensate
the merchant therefor. Then he shall obtain a receipt form the merchant
for the money that he gives the merchant.
        -- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/





More information about the Python-list mailing list