Grok, this was were I'm afraid for, I don't understand what you guru's are talking of :-(. I can follow partly, but not the essence. But, thanks for giving me a solution. It's better to know that you still have to learn much then just getting the answer that it isn't possible. Since I haven't asked this q'n directly here -the question which has given me already 3 days of headache-, perhaps some of you can share me your idea on how to solve this problem. (The q'ns I asked before on this list are directly descending from this q'n): How can a ZClass know when it is moved and how can you add some code to it, so this code is executed when the ZClass is moved. Tom. At 03:51 07/03/2000 -0800, Michel Pelletier wrote:
Tom Deprez wrote:
"Quote Martijn" im_func is a part of Python introspection. It is the pure function definition of a class, not bound to that class, so I can pass in an alternate self.
Aiee! Split personality objects!
I am trying to call a superclass method here, and normally CatalogAware.index_object() would suffice. But because of Extension Classes, Python gets confused as to what is a class method, and what is a regular function. It will accuse me of calling an unbound method, which of course I am not. I circumvent this by calling the unbound function, and passing in self explicitly.
Then this sounds like a bug in ExtensionClass, shouldn't it be able to grock that CatalogAware.method(instance) is a class method bound to instance?
Dammit I've seen this somewhere before... ah, this might be it, quothe the ExtensionClass documetation:
Overriding methods inherited from Python base classes
A problem occurs when trying to overide 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(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').
MP> ^^^^^^^^ This sounds like your problem right here ^^^^^^^^
To overcome this problem, extension classes provide a class method 'inheritedAttribute' that can be used to obtain an inherited attribute that is suitable for calling with an extension class instance. Using the 'inheritedAttribute' method, the above example can be rewritten as::
from ExtensionClass import Base
class Spam:
def __init__(self, name): self.name=name
class ECSpam(Base, Spam):
def __init__(self, name, favorite_color): ECSpam.inheritedAttribute('__init__')(self,name) self.favorite_color=favorite_color
This isn't as pretty but does provide the desired result.
I don't think, however, that this can be used called from an external method. There is no access to whatever class your method is a shared attribute of ('self' in an external method could be bound to all sorts of class instances depending on how it is called). I could be completely wrong.
-Michel