[CentralOH] __metaclass__

Mark Erbaugh mark at microenh.com
Fri Jun 27 02:31:37 CEST 2008

On Thu, 2008-06-26 at 12:31 -0400, Steven Huwig wrote:
> I tried to replicate this on my 2.5.2 install and was unable to do it.
> Do you have a minimum failing example?

I figured it out.  The problem was with the metaclass.  I designed the
base class (Query) to be sub-classed. I didn't want the metaclass to do
anything to the base class, just to sub-classes, so the metaclass's
__init__ starts:

    def __init__(cls, name, t, d):
        if name <> 'Query':

Thus the stuff that I wanted to happen wasn't happening if the sub-class
was also named 'Query'.

So I changed the code:

    def __init__(cls, name, t, d):
        # if name <> 'Query':
        if cls.__base__ <> object:

I originally tried
	if cls <> Query:

But Python complained about unknown Query. Query was declared later in
the same file.  I tried swapping Query and the metaclass, but then I got
complaints about the metaclass being unkown in the definition of Query:


More information about the CentralOH mailing list