[Zope] Problems with inheritance in python base products
Robert Leftwich
robert@leftfieldcorp.com
Sun, 17 Oct 1999 18:44:10 +1000
The problem stems from the use of ExtensionClass, this snippet from
http://www.digicool.com/releases/ExtensionClass explains :
----------------------------------------------------------------------------
--------------------
A problem occurs when trying to override methods inherited from Python base
classes. Consider the following example:
from ExtensionClass import Base
class Spam:
def __init__(self, name):
self.name=name
class ECSpam(ExtensionClass.Base, Spam):
def __init__(self, name, favorite_color):
Spam.__init__(self,name)
self.favorite_color=favorite_color
This implementation will fail when an ECSpam object is instantiated. The
problem is that ECSpam.__init__ calls Spam.__init__, and Spam.__init__ can
only be called with a Python instance (an object of type "instance") as the
first argument. The first argument passed to Spam.__init__ will be an ECSpam
instance (an object of type ECSPam).
----------------------------------------------------------------------------
--------------------
In order to access the base you need to use :
B.inheritedAttribute('__init__')(self,some, more)
Unfortunately, this only works in single inheritance hierarchies.
Robert Leftwich
> -----Original Message-----
> From: Sascha Matzke [mailto:sascha@bespin.escape.de]On Behalf Of Sascha
> Matzke
> Sent: Sunday, 17 October 1999 12:07
> To: zope@zope.org
> Subject: [Zope] Problems with inheritance in python base products
>
>
> Hello,
>
> I want to design 2+ products which all share certain base
> functionality. So I moved some code into Shared.
>
> Now, when I try to create instances of the products I get the
> following error:
>
> Error Type: TypeError
> Error Value: unbound method must be called with class instance 1st
> argument
>
> I use the following code:
>
> class B(A):
>
> def __init__(self, some, more, parameters):
> A.__init__(self, some, more)
>
> In my python knowlegde the above should be correct...
>
> Any hints...
>
> Sascha
> PS: I know ZClasses, but I want to use pure python for comfort
> reasons...
> --
> .-> Sascha Matzke - sascha@bespin.de - http://www.bespin.de -.
> | Das Kapital ist die Flamme, der Faschismus das Benzin |
> | Anarchist Academy |
> `-- On this earth for 24 years, 3 days <----------------'
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://www.zope.org/mailman/listinfo/zope
>
> (Related lists - please, no cross posts or HTML encoding!
>
> To receive general Zope announcements, see:
> http://www.zope.org/mailman/listinfo/zope-announce
>
> For developer-specific issues, zope-dev@zope.org -
> http://www.zope.org/mailman/listinfo/zope-dev )
>