Is there a way to ask a class what its metaclasses are ?

Barak, Ron Ron.Barak at lsi.com
Sun Feb 22 08:14:28 EST 2009


Hi Chris,

> -----Original Message-----
> From: chris at rebertia.com [mailto:chris at rebertia.com] On
> Behalf Of Chris Rebert
> Sent: Sunday, February 22, 2009 13:57
> To: Barak, Ron
> Cc: python-list at python.org
> Subject: Re: "metaclass conflict" error: where is noconflict ?
>
> On Sun, Feb 22, 2009 at 3:31 AM, Barak, Ron <Ron.Barak at lsi.com> wrote:
> <snip>
> >> > Applying your suggestion:
> >> >
> >> > class ListControlMeta(type(wx.Frame), type(CopyAndPaste)):
> >> >     pass
> >> >
> >> > class ListControl(wx.Frame, CopyAndPaste):
> >> >     def __init__(self, parent, id, title, list, max_list_width,
> >> > log_stream,
> >> > style=wx.DEFAULT_FRAME_STYLE):
> >> >
> >> >         __metaclass__= ListControlMeta
> >> >
> >> >
> >> > wx.Frame.__init__(self,parent,id,title,size=(max_list_width,-1),
> >> > style=style)
> >> >         self.list = list
> >> >         self.log_stream = log_stream
> >> >         self.list_ctrl = wx.ListCtrl(self, -1,
> style=wx.LC_REPORT |
> >> > wx.LC_NO_HEADER)
> >> >         self.list_ctrl.InsertColumn(0, title)
> >> >         for i,line_ in enumerate(list):
> >> >             self.list_ctrl.InsertStringItem(i, line_)
> >> >                 ...
> >> >
> >> > I get:
> >> >
> >> > $ python -u ./failover_pickle_demo09.py Traceback (most
> recent call
> >> > last):
> >> >   File "./failover_pickle_demo09.py", line 319, in <module>
> >> >     class ListControlMeta(type(wx.Frame), type(CopyAndPaste)):
> >> > TypeError: Error when calling the metaclass bases
> >> >     multiple bases have instance lay-out conflict
> >>
> >> >From what I recall, that basically means that type(wx.Frame) and
> >> type(CopyAndPaste) are both C classes that are are mutually
> >> incompatible. It's basically the same reason you can't
> subclass from
> >> both `list` and `dict` or two other built-in types (you
> get the exact
> >> same error).
> >>
> >> Sounds like the only way to workaround this would be to do some
> >> coding in C or to use composition rather than inheritance
> for one of
> >> ListControl's superclasses.
> >
> > The wx.Frame may be coded in C, but the CopyAndPaste class,
> which I wrote, is not (see it's listing below).
> > Could you have a look at the CopyAndPaste class, and see if
> something in its construction strikes you as susspicious ?
> >
> > Thanks,
> > Ron.
> >
> > $ cat ./CopyAndPaste.py
> > #!/usr/bin/env python
> >
> > import wx
> >
> > class CopyAndPaste():
>
> You need to subclass 'object' so as to make CopyAndPaste a
> new-style class. This may or may not resolve the error, but
> you should be doing it either way.
>
> class CopyAndPaste(object):
>
> Cheers,
> Chris
>

Thanks for the super-prompt replies.

Is there a way to ask a class what its metaclasses are ?
(e.g., how to ask wx.Frame what it's metaclass is)


I'm asking, because, even subclassing from object, viz.:

class CopyAndPaste(object):
    def __init__(self):
        pass
...

Still gives me:

$ python -u ./failover_pickle_demo09.py
Traceback (most recent call last):
  File "./failover_pickle_demo09.py", line 321, in <module>
    class ListControlMeta(wx.Frame, CopyAndPaste):
TypeError: Error when calling the metaclass bases
    metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

Bye,
Ron.

> --
> Follow the path of the Iguana...
> http://rebertia.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090222/3a6ec8f5/attachment-0001.html>


More information about the Python-list mailing list