Question about accessing class-attributes.

Michael Hudson mwh at python.net
Fri Apr 25 09:52:21 EDT 2003


Thomas Heller <theller at python.net> writes:

> Michael Hudson <mwh at python.net> writes:
> 
> > mis6 at pitt.edu (Michele Simionato) writes:
> > 
> > > The meta-type conflict is rather annoying, indeed. According to the
> > > metaclass book, the language should generate the correct metaclass
> > > that solves the conflict automatically, without burden for the
> > > programmer. Python is not that magic (yet) therefore you have to
> > > solve the conflict yourself.
> > 
> > I guess a potential problem is that if you do
> > 
> > class C(object):
> >     __metaclass__ = A
> > 
> > class D(object):
> >     __metaclass__ = B
> > 
> > class E(C, D):
> >     pass
> > 
> > class F(C, D):
> >     pass
> > 
> > you'd like both E and F to have the *same* (rather than merely
> > equivalent) metaclasses.  This would seem to be tricky to arrange.
> 
> Wouldn't a caching class factory be able to do this?

Yes.  I only said "tricky", not impossible.

class MetaGit(type):
    def __eq__(self, other):
        # aha! this makes class objects unhashable, cackle!
        return self is other

I don't know whether you want to cope with things like that.

Cheers,
M.

-- 
  Just point your web browser at http://www.python.org/search/ and
  look for "program", "doesn't", "work", or "my". Whenever you find
  someone else whose program didn't work, don't do what they
  did. Repeat as needed.    -- Tim Peters, on python-help, 16 Jun 1998




More information about the Python-list mailing list