Question about accessing class-attributes.

Bjorn Pettersen BPettersen at
Thu Apr 24 17:44:51 CEST 2003

> From: Duncan Booth [mailto:duncan at] 
> Alex Martelli <aleax at> wrote in 
> news:EARpa.120$3M4.2728 at
> > ..isn't this smoother and handier?  Or does it just look that way
> > to me, due to overexposure to custom metaclasses?-)
> > 
> Yes, I agree that it is better, but I have one niggling worry 
> about this:
> Your metaclass works fine for the one requirement given here, 
> and other metaclasses you have proposed work fine in their 
> place, but > what happens if you want to combine these and 
> get e.g. a Bunch which counts its instances?

Well, for some reason Python requires that if C1.__metaclass__ == M1,
C2.__metaclass__ == M2, and C2 is a subclass of C1, then M2 must be a
subclass of all metaclasses of of C2.__bases__, in particular M1. I
haven't seen a rationale for this (and it intuitively seems like an
arbitrary restriction... E.g. given two objects a and b, if b is a
subtype of a, i.e. if fn(b) and fn(a) both work [trying not to mention
contravariance], why would you expect a.__class__ and b.__class__ to
have any relation? [translate obj->class

-- bjorn

More information about the Python-list mailing list