I just installed the product ZGDChart-0.6.5.tar.gz. It unpacks and installs, but when I try to make an instance it dies with the diagnostic ----------- TypeError Exception Value unbound method __init__() must be called with instance as first argument Traceback (innermost last): * Module ZPublisher.Publish, line 98, in publish * Module ZPublisher.mapply, line 88, in mapply * Module ZPublisher.Publish, line 39, in call_object * Module Products.ZGDChart.ZGDChart, line 86, in manage_addZGDChart * Module Products.ZGDChart.ZGDChart, line 200, in __init__ TypeError: unbound method __init__() must be called with instance as first argument ---------- under Zope 2.6.2b3 with Python 2.1.3. The error seems to be here: def __init__(self, id='ZGDChart', title='ZGDChart', height=250, width=250, SQL=None, chart_type='Bar_3D', option=['xaxis', 'yaxis', 'grid', 'border']): GDChart.GDChart.__init__(self, id=id, title=title, height=height, width=width, SQL=SQL, chart_type=chart_type, option=option) The value of self passed in to GDChart.GDChart.__init__ is not a ZGDChart instance as I would have expected, but a string. Any suggestions? fixes?
Dennis Allison wrote at 2004-2-9 09:25 -0800:
I just installed the product ZGDChart-0.6.5.tar.gz. It unpacks and installs, but when I try to make an instance it dies with the diagnostic ----------- TypeError Exception Value unbound method __init__() must be called with instance as first argument ... The error seems to be here:
def __init__(self, id='ZGDChart', title='ZGDChart', height=250, width=250, SQL=None, chart_type='Bar_3D', option=['xaxis', 'yaxis', 'grid', 'border']):
GDChart.GDChart.__init__(self, id=id, title=title, height=height, width=width, SQL=SQL, chart_type=chart_type, option=option)
Change this to: __super_init = GDChart.GDChart.__init__ def __init__(self, id='ZGDChart', title='ZGDChart', height=250, width=250, SQL=None, chart_type='Bar_3D', option=['xaxis', 'yaxis', 'grid', 'border']): self.__super_init(id=id, title=title, height=height, width=width, SQL=SQL, chart_type=chart_type, option=option) This is the standard way to work around such "TypeError"s. The "ExtensionClass" documentation tells you why this error occurs and a different work around. -- Dieter
On Tuesday 10 February à 19:36, Dieter Maurer wrote:
Dennis Allison wrote at 2004-2-9 09:25 -0800:
I just installed the product ZGDChart-0.6.5.tar.gz. It unpacks and installs, but when I try to make an instance it dies with the diagnostic ----------- TypeError Exception Value unbound method __init__() must be called with instance as first argument ... The error seems to be here:
def __init__(self, id='ZGDChart', title='ZGDChart', height=250, width=250, SQL=None, chart_type='Bar_3D', option=['xaxis', 'yaxis', 'grid', 'border']):
GDChart.GDChart.__init__(self, id=id, title=title, height=height, width=width, SQL=SQL, chart_type=chart_type, option=option)
Change this to:
__super_init = GDChart.GDChart.__init__
def __init__(self, id='ZGDChart', title='ZGDChart', height=250, width=250, SQL=None, chart_type='Bar_3D', option=['xaxis', 'yaxis', 'grid', 'border']):
self.__super_init(id=id, title=title, height=height, width=width, SQL=SQL, chart_type=chart_type, option=option)
This is the standard way to work around such "TypeError"s.
The "ExtensionClass" documentation tells you why this error occurs and a different work around.
I've encountered a similar problem which I could not understand for now: I've a Zope product using a regular python package. The problem is that the same kind of TypeError is raised _in the python package_, where no class knows anything about ExtensionClass (I mean there is no ExtensionClass.Base in the classes hierarchy) ! I can't find this documented anywhere. Does someone ever encountered such a problem ? Or does someone could affirm that this is impossible, and the product is doing something nasty ? Using the same trick as Dieter explained fixes the problem, but I really don't feel good to have to do this in an external product. -- Sylvain Thénault LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Sylvain Thénault wrote at 2004-2-11 23:49 +0100:
... I've encountered a similar problem which I could not understand for now: I've a Zope product using a regular python package. The problem is that the same kind of TypeError is raised _in the python package_, where no class knows anything about ExtensionClass (I mean there is no ExtensionClass.Base in the classes hierarchy) !
Does your product inherit from a class defined by this "regular python package"? Then you have this same situation: "self" is an ExtensionClass instance. When your ExtensionClass unaware class "C" uses "C'.method(self,...)" (where "C'" is an ExtensionClass unaware base class of "C"), then you get the mentioned "TypeError". The easiest solution is to make the base class ExtensionClass aware (i.e. inherit from "ExtensionClass.Base"). But, this requires modification of your regular package. As an alternative: you must override the problematic method and use the technique either described in this thread or that in the "ExtensionClass" documentation. -- Dieter
On Thursday 12 February à 21:19, Dieter Maurer wrote:
Sylvain Thénault wrote at 2004-2-11 23:49 +0100:
... I've encountered a similar problem which I could not understand for now: I've a Zope product using a regular python package. The problem is that the same kind of TypeError is raised _in the python package_, where no class knows anything about ExtensionClass (I mean there is no ExtensionClass.Base in the classes hierarchy) !
Does your product inherit from a class defined by this "regular python package"?
Then you have this same situation:
"self" is an ExtensionClass instance.
When your ExtensionClass unaware class "C" uses "C'.method(self,...)" (where "C'" is an ExtensionClass unaware base class of "C"), then you get the mentioned "TypeError".
Yes, I think I understand well that case. I've tried this approach in a first draft of the product but finally abandoned it because it was to messy. Now, the zope classes are totally separated from the classes of the python package, there is no inheritance link between them. When I need to use the python package, I build a new model with the python package's classes by visiting zope classes instances to create an equivalent model. And sometimes, I get this error in the python package while constructing the equivalent model... Gasp ! -- Sylvain Thénault LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org
participants (3)
-
Dennis Allison -
Dieter Maurer -
Sylvain Thénault