[Zope] Inheritance and __init__
TFE MMS JARVIS JOHN
jarvis.sd082@ex.tel.co.jp
Mon, 12 Apr 1999 19:06:06 +0900
I think I found the answer:
http://www.digicool.com/releases/ExtensionClass/ExtensionClass.html
Changing the code for Zope to
B.Zope:
#--nothing.py--
<Various imports, etc.>
from ExtensionClass import Base ###Added
import supernothing
class nothing(Base, ###Added
supernothing.Supernothing, ##Changed position
Acquisition.Implicit,
Persistent,
AccessControl.Role.RoleManager,
OFS.SimpleItem.Item
):
"""Blank skeleton class.
""""
<Various manage settings, etc>
def __init__(self,id,title,greeting):
self.id=id
self.title=title
nothing.inheritedAttribute('__init__')(self,greeting) ##Changed
<the rest...>
Fixes it.
All I can guess is that my base class and the Zope base classes
were clashing somehow?
I won't even try to pretend that I understand. ;^)
Back to the mill...
John Jarvis
> -----Original Message-----
> From: TFE MMS JARVIS JOHN [SMTP:jarvis.sd082@ex.tel.co.jp]
> Sent: Monday, April 12, 1999 4:16 PM
> To: zope@zope.org
> Subject: [Zope] Inheritance and __init__
>
> Hi!
>
> I'm kind of stuck:
> I'm trying to write a product that is a subclass of some other class
> that I wrote for something else. I'm having a problem with calling
> the superclass's __init__ method from within the subclass's
> __init__ method.
>
> It works within Python but not Zope. ?
>
> I don't have any comprehensible code to show, so here's
> some test code I've been using:
>
> The superclass:
>
> #--supernothing.py--
> class Supernothing:
> def __init__(self,greeting="hello"):
> self.greeting=greeting
>
> def sayhi(self):
> return self.greeting
>
> The subclasses look something like:
>
> A.Python only:
> #--subnothing.py --
> import supernothing
> class Subnothing(supernothing.Supernothing):
> def __init__(self,greeting="I'm here!"):
> supernothing.Supernothing.__init__(self,greeting)
>
> B.Zope:
> #--nothing.py--
> <Various imports, etc.>
> import supernothing
> class nothing(Acquisition.Implicit,
> Persistent,
> AccessControl.Role.RoleManager,
> OFS.SimpleItem.Item,
> supernothing.Supernothing):
> """Blank skeleton class.
>
> """"
>
> <Various manage settings, etc>
>
> def __init__(self,id,title,greeting):
> self.id=id
> self.title=title
> supernothing.Supernothing.__init__(self,greeting) # This is line
> 50
>
> <bunch of other stuff>
>
> def addNothing(self,id,title,REQUEST=None,greeting='I am nothing!'):
> """Add a Nothing object.
>
> """
> obj=nothing(id,title, greeting)
> self._setObject(id,obj)
>
> <the rest...>
>
> Version A works (in the Python interpreter, of course). Version B
> gives an error(in Zope):
> Traceback (innermost last):
> File /usr/lib/python1.5/ZPublisher/Publish.py, line 877, in
> publish_module
> File /usr/lib/python1.5/ZPublisher/Publish.py, line 590, in publish
> (Info: /queries/pictest/manage_addNothing)
> File /usr/lib/python1.5/Products/nothing/nothing.py, line 81, in
> addNothing
> (Object: Navigation)
> File /usr/lib/python1.5/Products/nothing/nothing.py, line 50, in
> __init__
> (Object: RoleManager)
> TypeError: unbound method must be called with class instance 1st argument
>
> Can anyone see what I am missing here?
>
> TIA!
> John Jarvis
>
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://www.zope.org/mailman/listinfo/zope
>
> (For developer-specific issues, use the companion list,
> zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )