[Zope-dev] Calling from an Overriding function

Robert Leftwich robert@leftfieldcorp.com
Mon, 29 Nov 1999 08:15:21 +1100


The error 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)

OR in your case

CatalogAware.inheritedAttribute( 'manage_beforeDelete' )(self, item,
container)

Unfortunately, this currently only works in single inheritance hierarchies.

Robert Leftwich

> -----Original Message-----
> From: itamar@localhost.localdomain
> [mailto:itamar@localhost.localdomain]On Behalf Of Itamar Shtull-Trauring
> Sent: Sunday, 28 November 1999 22:15
> To: zope-dev@zope.org
> Subject: [Zope-dev] Calling from an Overriding function
>
>
> I'm trying to override manage_beforeDelete(self,item,container)
> in a python
> class that
> inherits CatalogAware.
> The overriding manage_beforeDelete calls the base class function:
>
>
>
> from Products.ZCatalog.CatalogAwareness import CatalogAware
>
> class Workflow(CatalogAware):
>
>     def
> manage_beforeDelete(self,item,container):
>
> """
> """
>
> 	...
>
> 	CatalogAware.manage_beforeDelete(self, item, container)
>
>
>
>
> I get this error message:
>
> Error Type: TypeError
> Error Value: unbound method must be called with class instance
> 1st argument
>
>
>
>
> --
> Itamar S.T.  itamars@ibm.net
>
> _______________________________________________
> Zope-Dev maillist  -  Zope-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zope-dev
>            No cross posts or HTML encoding!
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope )
>