Using metaclasses to make super more beatiful

Gerrit Holl gerrit at nl.linux.org
Thu Jun 5 22:01:42 CEST 2003


Gerrit Holl schreef op donderdag  5 juni om 21:10:05 +0000:
> > >  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 don't get it. What is the essential difference between this and
Guido's example on http://www.python.org/2.2.3/descrintro.html#metaclasses?

yours,
Gerrit.

-- 
167. If a man marry a wife and she bear him children: if this wife die
and he then take another wife and she bear him children: if then the
father die, the sons must not partition the estate according to the
mothers, they shall divide the dowries of their mothers only in this way;
the paternal estate they shall divide equally with one another.
        -- 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