problem with hack using multiple inheritance for plugins
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Jun 28 07:45:34 EDT 2007
massimo s. a écrit :
>> At this point, it seems too much a deep object-oriented hell to be
>> able to dig it myself. Would you help me getting some cue on the
>> problem?
>
> Update. Now I know that:
> - every sane Python class should return <type 'instance'> after
> type(self)
Certainly not, unless you're using a pretty old Python version.
'instance' type means old-style classes - the legacy Python object
model, replaced some years ago with a *much* better one ('new-style'
classes). IIRC, this (now dying) legacy object model should disappear
with Py3K.
> - when disabling the multiple-inheritance-hack, the situation comes
> back to normal
I may be wrong here - I don't use old-style classes, and I avoid
multiple inheritance whenever I can - but I think this may has to do
with mixing old-style and new-style classes.
> What happens that makes the wxFrame class different from the cmd.Cmd
> class?
wxFrame is obviously a new-style class.
<side-note>
wrt/ this snippet:
for plugin_name in self.config['plugins']:
try:
plugin=__import__(plugin_name)
try:
print type(self)
eval('plugin.'+plugin_name+'Commands._plug_init(self)')
except AttributeError:
pass
except ImportError:
pass
You may want to try this instead:
for plugin_name in self.config['plugins']:
try:
plugin=__import__(plugin_name)
except ImportError:
# eventually do something like logging the error ?
continue
try:
cmdplug = getattr(plugin, plugin_name+'Commands')
cmdplug._plug_init(self)
except AttributeError:
# eventually do something like logging the error ?
continue
</side-note>
More information about the Python-list
mailing list