[Zope] Re: Error:unbound method __init__() must be called with
instance as first argument
Casey Duncan
casey at zope.com
Mon Apr 12 13:34:34 EDT 2004
On Fri, 9 Apr 2004 16:28:38 +0400
"Serg" <sutni at yandex.ru> wrote:
> --- file A.py ---
> class CA:
> "class for my needs"
> def __init__(self, a=0):
> "init"
> self.__a=a
>
> --- file B.py ---
> from A import CA
> from OFS import SimpleItem
> class CB(SimpleItem.SimpleItem , CA ):
> "class B"
> def __init__(self, id, docN):
> "init"
> CA.__init__(self)
> self.id=id
> self.docN=docN
>
> On add object of CB Zope write:
> Site Error
> An error was encountered while publishing this resource.
> Error Type: TypeError
> Error Value: unbound method __init__() must be called with
> instance
> as first argument
>
> Where is this Error?
The error is that CB and CA are different types. CA is a classic python
class. CB is an ExtensionClass (because it subclasses SimpleItem which
subclasses ExtensionClass.Base). Python is preventing you from binding
the non-extension class CA to the CB extension class intance.
A solution is to make CA an extension class::
import ExtensionClass
class CA(ExtensionClass.Base):
...
Then delegating to CA's __init__ from CB should work fine. This is the
reason why you will often see mix-in classes in Zope inherit from
ExtensionClass.Base even though they do not explicitly use its features.
-Casey
More information about the Zope
mailing list