How to get MRO in __new__() of metaclasses?

Michael Hudson mwh at python.net
Tue Dec 10 06:54:22 EST 2002


fvondelft at syrrx.com (Frank von Delft) writes:

> > Explaining what you're trying to acheive may (no promises :) help us
> > give better answers.
> 
> Sure, I here's the metaclass, with little illustrations;  check out
> the docstrings.  The bit I struggle with is marked with CAPS.
[...]
> I'm trying to provide base classes that don't allow derived classes
> too much freedom;  in particular, the base class provides methods and
> restrictions (i.e. propeties), while the derived classes does the
> configuration (i.e. setting of values).
>       Base (restricts)  --->  Deriv (configures)  --->  Object (uses)
> 
> I strongly suspect there may be a better way of doing this.  e.g.
> doing the configuration in Deriv.__init__() instead of with class
> variables, as in BadPrep (although I do want the configuration in
> Deriv to be automatically inherited);  or maybe with intelligent
> exceptions?  (Other suggestions?)   But I rather like properties, and
> at least I now grok metaclasses :-)

I think the easiest way of doing what you want may be to create the
class once, without frobbing, look at that to work out what you need
to tweak, throw it away, and build another class.

Which seems a bit of a hack, but I can't think of a better way.

I also slightly fail to understand why you can't just scan through the
immediate superclasses, but there may be something I've missed.

Cheers,
M.

-- 
  It could be argued that since Suitespot is infinitely terrible,
  that anything else, by very definition of being anything else,
  is infinitely superior.                -- ".", alt.sysadmin.recovery



More information about the Python-list mailing list