Inheritance (?) problem
Hi, I have a pure-python (no Zope classes around) 'form' class like this: class form: def __init__(self, id): self.id = id def actionTarget(self, REQUEST={}): "Main entry point." return 'foo'
From this class I derive a subclass
class zopeForm (SimpleItem.SimpleItem, form): def actionTarget(self, REQUEST={}): "Main entry point." # ... other thing done here... form.actionTarget (self, REQUEST) The zopeForm class is part of a product so I have instances of zopeForm (say 'zf') in a folder (say 'foo'). Now I would like to visit the URL ...../foo/zf/actionTarget but I get the following error: Error Type: TypeError Error Value: unbound method must be called with class instance 1st argument but 'self' in the call to form.actionTarget should be a zopeForm instance! If I change zopeForm.actionTarget to: def actionTarget(self, REQUEST={}): "Main entry point. Passing http REQUEST" raise self I get Error Type: TypeError Error Value: exceptions must be strings, classes, or instances and if I change it to: def actionTarget(self, REQUEST={}): "Main entry point. Passing http REQUEST" raise str(self) I get Error Type: Error Value: None It seems I'm missing something.... Any hint? TIA, Luca
Luca Manini writes:
I have a pure-python (no Zope classes around) 'form' class like this:
class form:
def __init__(self, id): self.id = id
def actionTarget(self, REQUEST={}): "Main entry point." return 'foo'
From this class I derive a subclass
class zopeForm (SimpleItem.SimpleItem, form):
def actionTarget(self, REQUEST={}): "Main entry point." # ... other thing done here... form.actionTarget (self, REQUEST)
The zopeForm class is part of a product so I have instances of zopeForm (say 'zf') in a folder (say 'foo'). Now I would like to visit the URL
...../foo/zf/actionTarget
but I get the following error:
Error Type: TypeError Error Value: unbound method must be called with class instance 1st argument
but 'self' in the call to form.actionTarget should be a zopeForm instance! This is an ExtensionClass/Python incompatibility, documented with ExtensionClass. You need "inheritedAttribute" to work around the problem, documented too.
Dieter
"Dieter" == Dieter Maurer <dieter@handshake.de> writes:
> Luca Manini writes: [...] When overriding a superclass (base) method (foo) in a subclass (sub), one often wants to call the inherited one. In 'pure' (bare?) Python you can do this: class sub (base): def foo(self, arg): sub.foo (self, arg) I tried this with sub inheriting from SimpleItem.SimpleItem and from an external 'pure python' class and it does not work. > This is an ExtensionClass/Python incompatibility, documented > with ExtensionClass. You need "inheritedAttribute" to work > around the problem, documented too. > Dieter As always, Dieter (thanks) solved the problem! . 1) documented means (I think) read ..../zope/lib/python/StructuredText/regressions/ExtensionClass.stx funny place for that piece of really interesting info. 2) You need inheritedAttribute means (I do that way and it works): class sub (base): def foo(self, arg): sub.inheritedAttribute ('foo') (self, arg) Any other trick like this in constructing (product's) Zope classes from 'pure-python' ones? I do prefere to have as much python code as possible out of Zope (so that it can be use without Zope), and overriding inherited methods is (I think) a very basic tool in this. bye, Luca
Luca Manini writes:
.... > This is an ExtensionClass/Python incompatibility, documented > with ExtensionClass. You need "inheritedAttribute" to work > around the problem, documented too. ... 1) documented means (I think) read
..../zope/lib/python/StructuredText/regressions/ExtensionClass.stx
funny place for that piece of really interesting info. A more natural place is ".../zope/lib/Components/ExtensionClass/doc"
Dieter
"Dieter" == Dieter Maurer <dieter@handshake.de> writes:
> A more natural place is > ".../zope/lib/Components/ExtensionClass/doc" There is no such file in my installation (Debian, zope Version: 2.3.3-1). Is that included in newer Zope, or in tarball/source/cvs version only? Is there more 'standard' docs like that I'm missing? bye, Luca
participants (2)
-
Dieter Maurer -
Luca Manini