Error:unbound method __init__() must be called with instance as first argument
--- 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? Regard, Serg.
Hi Try like this: CA.__dict__['__init__'](self) Regards, Dragos
--- 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?
Regard, Serg.
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Hi The idea is that using this form of calling the constructor no check is performed for the first argument. Here are 2 VERY usefull links to clarify this: http://www.daa.com.au/pipermail/pygtk/2001-May/001180.html http://mail.zope.org/pipermail/zope/2004-February/146824.html Regards, Dragos
Try like this:
CA.__dict__['__init__'](self)
Thanks. This cod work normally. But, tell me, please, why cod CA.__init__(self) dose not work properlly?
Regard Serg
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On Fri, 9 Apr 2004 16:28:38 +0400 "Serg" <sutni@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
participants (3)
-
Casey Duncan -
Dragos Chirila -
Serg