Multi Heritage with slots - Python

This is a discussion on Multi Heritage with slots - Python ; Hye, I'm developing a little app, and I want to make multi heritage. My problem is that my both parent do have __slots__ define. So I've got something like: class foo(object): __slots__ = ['a', 'b'] pass class foo2(object): __slots__ = ...

+ Reply to Thread
Results 1 to 6 of 6

Multi Heritage with slots

  1. Default Multi Heritage with slots

    Hye,

    I'm developing a little app, and I want to make multi heritage.
    My problem is that my both parent do have __slots__ define.

    So I've got something like:

    class foo(object):
    __slots__ = ['a', 'b']
    pass

    class foo2(object):
    __slots__ = ['c', 'd']
    pass

    class crash(foo, foo2):
    pass

    If you write only that in a sample file or in python console (as I
    did), python refuse to load the module and report something like:

    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    TypeError: Error when calling the metaclass bases
    multiple bases have instance lay-out conflict

    Do you know why it append? And how could I make this work?


  2. Default Re: Multi Heritage with slots

    On Wed, 05 Sep 2007 11:01:56 +0200, Alexandre Badez
    <alexandre.badez> wrote:

    > Hye,
    >
    > I'm developing a little app, and I want to make multi heritage.
    > My problem is that my both parent do have __slots__ define.
    >
    > So I've got something like:
    >
    > class foo(object):
    > __slots__ = ['a', 'b']
    > pass
    >
    > class foo2(object):
    > __slots__ = ['c', 'd']
    > pass
    >
    > class crash(foo, foo2):
    > pass
    >
    > If you write only that in a sample file or in python console (as I
    > did), python refuse to load the module and report something like:
    >
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in ?
    > TypeError: Error when calling the metaclass bases
    > multiple bases have instance lay-out conflict
    >
    > Do you know why it append? And how could I make this work?


    See http://mail.python.org/pipermail/pyt...er/418768.html

    Basically, the general advice you're likely to get here is: don't use
    __slots__, or at least don't use __slots__ with inheritance.

    BTW, what are you trying to do? Is it really a memory footprint
    optimization, which is the intended use case for __slots__, or are you
    just doing Java in Python?
    --
    python -c "print ''.join([chr(154 - ord(c)) for c in
    'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

  3. Default Re: Multi Heritage with slots

    On Sep 5, 12:42 pm, "Eric Brunel" <see.signat...@no.spam> wrote:
    > Seehttp://mail.python.org/pipermail/python-list/2006-December/418768.html
    >
    > Basically, the general advice you're likely to get here is: don't use
    > __slots__, or at least don't use __slots__ with inheritance.
    >
    > BTW, what are you trying to do? Is it really a memory footprint
    > optimization, which is the intended use case for __slots__, or are you
    > just doing Java in Python?
    > --
    > python -c "print ''.join([chr(154 - ord(c)) for c in
    > 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"


    Thanks for your answer.
    I use __slots__ not for memory optimization nor doing java.
    I use __slots__ because my class are used by other lib, and in the
    past, some of them misspell some attributes and involved a very
    annoying comportment of the global application.
    So the objective is only to prevent unwanted dynamism (but not in all
    the application, just some class).

    PS: I very like your signature


  4. Default Re: Multi Heritage with slots

    On 9/5/07, Alexandre Badez <alexandre.badez> wrote:
    > I use __slots__ not for memory optimization nor doing java.
    > I use __slots__ because my class are used by other lib, and in the
    > past, some of them misspell some attributes and involved a very
    > annoying comportment of the global application.
    > So the objective is only to prevent unwanted dynamism (but not in all
    > the application, just some class).


    Using slots to prevent the creation of new properties is what Eric
    *means* by "doing java". You're trying to write Java style code in
    Python, and it's not going to be pretty. Slots are not intended for
    this purpose, and they aren't very good for it.

    --
    Cheers,
    Simon B.
    simon@brunningonline.net
    http://www.brunningonline.net/simon/blog/
    GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues

  5. Default Re: Multi Heritage with slots

    On Sep 5, 2:52 pm, "Simon Brunning" <si...@brunningonline.net> wrote:
    > On 9/5/07, Alexandre Badez <alexandre.ba...> wrote:
    >
    > > I use __slots__ not for memory optimization nor doing java.
    > > I use __slots__ because my class are used by other lib, and in the
    > > past, some of them misspell some attributes and involved a very
    > > annoying comportment of the global application.
    > > So the objective is only to prevent unwanted dynamism (but not in all
    > > the application, just some class).

    >
    > Using slots to prevent the creation of new properties is what Eric
    > *means* by "doing java". You're trying to write Java style code in
    > Python, and it's not going to be pretty. Slots are not intended for
    > this purpose, and they aren't very good for it.
    >


    Right, and this the way to do what the original poster wants:

    http://aspn.activestate.com/ASPN/Coo.../Recipe/252158

    Michele Simionato


  6. Default Re: Multi Heritage with slots

    On Sep 5, 2:56 pm, Michele Simionato <michele.simion...>
    wrote:
    > On Sep 5, 2:52 pm, "Simon Brunning" <si...@brunningonline.net> wrote:
    >
    > > On 9/5/07, Alexandre Badez <alexandre.ba...> wrote:

    >
    > > > I use __slots__ not for memory optimization nor doing java.
    > > > I use __slots__ because my class are used by other lib, and in the
    > > > past, some of them misspell some attributes and involved a very
    > > > annoying comportment of the global application.
    > > > So the objective is only to prevent unwanted dynamism (but not in all
    > > > the application, just some class).

    >
    > > Using slots to prevent the creation of new properties is what Eric
    > > *means* by "doing java". You're trying to write Java style code in
    > > Python, and it's not going to be pretty. Slots are not intended for
    > > this purpose, and they aren't very good for it.

    >
    > Right, and this the way to do what the original poster wants:
    >
    > http://aspn.activestate.com/ASPN/Coo.../Recipe/252158
    >
    > Michele Simionato


    Thanks every body for your remarks.
    I still have a lot to learn in python...


+ Reply to Thread

Similar Threads

  1. Methods or class allocated slots
    By Application Development in forum lisp
    Replies: 5
    Last Post: 11-28-2007, 05:01 PM
  2. Print slots as html
    By Application Development in forum lisp
    Replies: 1
    Last Post: 08-06-2007, 02:23 AM
  3. xsd : heritage de deux types complexes
    By Application Development in forum XML SOAP
    Replies: 0
    Last Post: 04-27-2006, 10:44 AM
  4. if you are bored... ztk-slots game :-)
    By Application Development in forum Perl
    Replies: 2
    Last Post: 01-27-2005, 07:25 AM
  5. [ANN] Slots - a web framework in 2 classes
    By Application Development in forum Java
    Replies: 0
    Last Post: 08-09-2004, 11:12 AM