[PEAK] component metaclasses

Phillip J. Eby pje at telecommunity.com
Wed Apr 6 11:46:01 EDT 2005


At 09:05 PM 4/5/05 -0700, Jason wrote:
>Hello.  Is there a proper way to define components that have an
>additional metaclass?  I first figured I would make my metaclass a
>subclass of binding.Component's metaclass, but that wasn't so simple,
>at least for me.  What is Component's metaclass? :)

type(binding.Component) or binding.Component.__class__.  :)  In general in 
PEAK it's best not to make assumptions about the exact metaclass, because 
PEAK can create metaclasses on the fly, to support e.g. 'binding.classAttr' 
(which attaches a binding to the metaclass rather than the class, so that 
the attribute has a per-class value rather than a per-instance value).


>I ended up using the method described here:
>"Solving the Metaclass Conflict"
>http://www.phyast.pitt.edu/~micheles/python/metatype.html
>
>That works perfectly fine, but I'm curious if there's a simpler way.

Well, the peak.util.Meta module has a makeClass function that implements 
that same recipe.  (Michele independently invented the technique after it 
first appeared in TransWarp some years ago).

By the way, depending on the kind of metaclass you're creating, you might 
not need it at all.  The binding framework's metadata facilities eliminate 
most of the common reasons to have a metaclass, in my experience, and the 
ability to define "class attributes" takes care of automatically creating 
them for you under other circumstances.  Perhaps you could explain what 
you're trying to do with your metaclass.




More information about the PEAK mailing list