Question about accessing class-attributes.

Alex Martelli aleax at aleax.it
Thu Apr 24 17:21:57 EDT 2003


Duncan Booth wrote:

> Alex Martelli <aleax at aleax.it> wrote in
> news:EARpa.120$3M4.2728 at news1.tin.it:
> 
>> ..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?

You make a new metaclass multiply inheriting from the ones you have
(and solve conflicts as usual for multiple inheritance).


> I haven't tried it to see what happens, maybe you just need to indirect
> type.__new__ calls through super, and make a new submetaclass with the old
> metaclasses as bases, but I'd like to know if there are issues here or if
> I'm just worrying needlessly.

Both;-).  Yes, there are issues (custom metaclasses haven't been used
widely enough yet to shake out all the early problems -- I keep thinking
about them but I don't use them in production code yet, for example,
partly because I generally don't *need* the class-based functionality,
such as automatically counting instances, which is SO often requested
in this newsgroup!-).  However, I think that in general your worries may
be needless -- or at least, no more needful than any other worry that
relates to multiple inheritance, a construct that, of course, _does_
give you headaches SOME of the time.


Alex





More information about the Python-list mailing list