[Zope-dev] Extension class and __init__

Ross Boylan RossBoylan@stanfordalumni.org
Mon, 22 Jul 2002 00:30:34 -0700


I had the bright idea of defining a mixin class whose methods I
thought I could use in my regular Zope product classes:

class AMixin:
  def __init__(self):
     blah, blah blah

class B(AMixin, Persistent, Folder, ....):
  def __init__(self):
    # do some of my own stuff
    AMixin.__init__(self)

This fails with the warning (as I recall) that the unbound method
AMixin.__init__ needs to be called with an instance as its first
argument.  (I've stripped the example down to give what I think are
the essentials).

self in the context of B is an Extension class, and I'm guessing this
is making AMixin unhappy because it's not.  I assume I'll have the
same problem with other methods that I attempt to access using
AMixin.foo(self).

Can anyone confirm this diagnosis?  And what's the best solution?

I have redefined things
class AMixin:
  def _mixin_init(self):
    #stuff

class B(AMixin, .....):
   def __init__(self):
    #my own stuff
    self._mixin_init(self)

and this seems to work, but I wonder if there's a way to get the
classes to play together better (maybe "class AMixin(ExtensionClass):"?
though since ExtensionClass is a type I guess that's not exactly it).

This was after already discovering that isinstance doesn't work with
ExtensionClass (which I see confirmed on the list, along with the fact
that ExtensionClass generally has a lot of rough spots and may be on
the way out).  This is with Zope 2.5.1.