hello, I've a problem to have a class which inherits from zope base classes (Role.RoleManager, Acquisition.Implicit, ObjectManager.ObjectManager and Persistent) and classes from another package. As soon as a class inherits from one of the zope base class, I get an exception when I try to instantiate an object of this class. This exception is raised when I try to call the ancestor constructor: ZNodeImpl.__init__(self, id, title) TypeError: unbound method __init__() must be called with instance as first argument this sounds like my class doesn't inherit from ZNodeImpl but it does !! If I remove the zope base class, everything works correctly... it seems to have some python black magic here. Anybody can explain this to me or give some pointers ? TIA -- Sylvain Thénault
Hi Sylvain, See the description of "inheritedAttribute" in this document: http://debian.acm.ndsu.nodak.edu/doc/python-extclass/ExtensionClass.html Almost all Zope objects are extension classes and they play by slightly different rules than vanilla Python classes. - C On Thu, 2002-06-06 at 11:53, Sylvain Thénault wrote:
hello,
I've a problem to have a class which inherits from zope base classes (Role.RoleManager, Acquisition.Implicit, ObjectManager.ObjectManager and Persistent) and classes from another package. As soon as a class inherits from one of the zope base class, I get an exception when I try to instantiate an object of this class. This exception is raised when I try to call the ancestor constructor:
ZNodeImpl.__init__(self, id, title) TypeError: unbound method __init__() must be called with instance as first argument
this sounds like my class doesn't inherit from ZNodeImpl but it does !! If I remove the zope base class, everything works correctly...
it seems to have some python black magic here. Anybody can explain this to me or give some pointers ?
TIA
-- Sylvain Thénault
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
On Thursday 06 June à 11:59, Chris McDonough wrote:
Hi Sylvain,
See the description of "inheritedAttribute" in this document:
http://debian.acm.ndsu.nodak.edu/doc/python-extclass/ExtensionClass.html
Almost all Zope objects are extension classes and they play by slightly different rules than vanilla Python classes.
- C
ok, I see my problem now. However, this document says it can be resolved with the inheritedAttribute class method but without talking about multiple inheritance. In my case, i have to call __init__ on different super classes, and inheritedAttribute does not provide a way to tell him on which super class __init__ should be call. Any idea ? -- Sylvain Thénault
You may need to trick the machinery with code like BaseClass.__dict__['__init__'](self, arg1, arg2, ...) Stefan --On Freitag, 07. Juni 2002 09:29 +0200 Sylvain Thénault <thenault@nerim.net> wrote:
On Thursday 06 June à 11:59, Chris McDonough wrote:
Hi Sylvain,
See the description of "inheritedAttribute" in this document:
http://debian.acm.ndsu.nodak.edu/doc/python-extclass/ExtensionClass.html
ok, I see my problem now. However, this document says it can be resolved with the inheritedAttribute class method but without talking about multiple inheritance. In my case, i have to call __init__ on different super classes, and inheritedAttribute does not provide a way to tell him on which super class __init__ should be call. Any idea ?
-- BLOWFISH, n. - Preference for beef.
This wont work either I'm afraid. Unfortunately if you need to call multiple base class __inits__, the best solution is just to duplicate the code from those inits in your subclass. - C On Fri, 2002-06-07 at 05:12, Stefan H. Holek wrote:
You may need to trick the machinery with code like
BaseClass.__dict__['__init__'](self, arg1, arg2, ...)
Stefan
--On Freitag, 07. Juni 2002 09:29 +0200 Sylvain Thénault <thenault@nerim.net> wrote:
On Thursday 06 June à 11:59, Chris McDonough wrote:
Hi Sylvain,
See the description of "inheritedAttribute" in this document:
http://debian.acm.ndsu.nodak.edu/doc/python-extclass/ExtensionClass.html
ok, I see my problem now. However, this document says it can be resolved with the inheritedAttribute class method but without talking about multiple inheritance. In my case, i have to call __init__ on different super classes, and inheritedAttribute does not provide a way to tell him on which super class __init__ should be call. Any idea ?
-- BLOWFISH, n. - Preference for beef.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Sylvain =?iso-8859-1?Q?Th=E9nault?= writes:
On Thursday 06 June à 11:59, Chris McDonough wrote:
See the description of "inheritedAttribute" in this document: ok, I see my problem now. However, this document says it can be resolved with the inheritedAttribute class method but without talking about multiple inheritance. The problem only occurs when you try to call a method inherited from a plain Python class (and not an ExtensionClass) from an ExtensionClass object (more precisely, pass an ExtensionClass object as "self" argument). You can safely use the standard way "klass.method(self,...)", when "klass" is itself an extension class.
That said, you can use the following work around: Wrap your plain Python class into an ExtensionClass and use that for explicitely calling the methods: class myPlainPythonClass: ... from ExtensionClass import Base class myWrappedPythonClass(Base,myPlainPythonClass): pass Of couse, you can give the wrapped class the same name as the plain class in order to minimize modifications of your code. Dieter
Sylvain Thénault <thenault@nerim.net> wrote:
I've a problem to have a class which inherits from zope base classes (Role.RoleManager, Acquisition.Implicit, ObjectManager.ObjectManager and Persistent) and classes from another package. As soon as a class inherits from one of the zope base class, I get an exception when I try to instantiate an object of this class. This exception is raised when I try to call the ancestor constructor:
ZNodeImpl.__init__(self, id, title) TypeError: unbound method __init__() must be called with instance as first argument
this sounds like my class doesn't inherit from ZNodeImpl but it does !! If I remove the zope base class, everything works correctly...
it seems to have some python black magic here. Anybody can explain this to me or give some pointers ?
That's weird because I've used it a number of times. For instance: class PortalContentFolder(PortalFolder, PortalContent, DefaultDublinCoreImpl): #... def __init__(self, id, title='', **kw): DefaultDublinCoreImpl.__init__(self) self.id = id self.title = title Florent -- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com
Florent Guillaume <fg@nuxeo.com> wrote: Hm, correct indentation would be: class PortalContentFolder(PortalFolder, PortalContent, DefaultDublinCoreImpl): #... def __init__(self, id, title='', **kw): DefaultDublinCoreImpl.__init__(self) self.id = id self.title = title Florent -- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com
All your classes are derived from ExtensionClass.Base. The problem is to call __init__() of a plain (non-EC) base class. However, what I have posted before works for me:
from ExtensionClass import Base
class Spam: ... def __init__(self, name): ... self.name = name ... class ECSpam(Base, Spam): ... def __init__(self, name, color): ... Spam.__dict__['__init__'](self, name) ... self.color = color ... spam = ECSpam('fred', 'blue') spam.name 'fred' spam.color 'blue'
Stefan --On Freitag, 07. Juni 2002 15:59 +0000 Florent Guillaume <fg@nuxeo.com> wrote:
That's weird because I've used it a number of times. For instance:
class PortalContentFolder(PortalFolder, PortalContent, DefaultDublinCoreImpl): #... def __init__(self, id, title='', **kw): DefaultDublinCoreImpl.__init__(self) self.id = id self.title = title
Florent
-- BLOWFISH, n. - Preference for beef.
participants (5)
-
Chris McDonough -
Dieter Maurer -
Florent Guillaume -
Stefan H. Holek -
Sylvain Thénault