[Zope] Help subclassing a non Zope class as base class of a product

Gilles Lenfant gilles@objectis.net
Tue, 21 May 2002 15:40:18 +0200


Hi,

I got a strange behaviour when subclassing a non Zope class (called
MyBase) that has - and needs - an __init__(...) by another class that
provides Zope features (called MyZSub).

from OFS.SimpleItem import SimpleItem
from mybase import MyBase
...

def manage_addMyZSub(self, id, title=3D'', REQUEST=3DNone):
    o =3D MyZSub(id, title)
    self._setObject(id, o)
    ...

class MyZSub(SimpleItem, MyBase):
    ...
    def __init__(self, id, title=3D''):
        self.id =3D id
        self.title =3D title
        # isinstance(self, MyZSub) -> 1 :)
        # isinstance(self, MyBase) -> 0 :(
        # (very strange)
        # THIS RAISES THE EXCEPTION BELOW
        MyBase.__init__(self)
        ...

Creating a new MyZSub object raises this !!!

Error Type: TypeError
Error Value: unbound method __init__() must be called with instance
as first argument.

I can't get what happens. Is "self" something else than the newly
created object when in such a class !!!???
When removing this line, it works (except of course there's no
construction of the base class 8((
This (MyBase.__init__(self)) works perfectly when subclassing MyBase
by any non Zope test class - including with multiple inheritance !!!

I can't understand why "self" is not instance of MyBase !!!

>>> class a: pass
>>> class b: pass
>>> class c(a, b): pass
>>> x=3Dc()
>>> isinstance(x, a)
1
>>> isinstance(x, b)
1

I made a quick hack tour in the Zope products installed in my serer
and I didn't notice any product trying to call the constructor of its
base class from its own constructor.

Has someone a hint. Please, I'm falling into a nervous breakdown...

Thanks in advance.

--Gilles