flori fgrimm at inneo.de
Mon Nov 10 16:49:27 CET 2003

fgrimm at inneo.de (flori) wrote in message news:<9d5f9ae4.0311070836.7503de86 at posting.google.com>...
> i try to greate somthing like this
sorry for silly question
my prob is when i try to do this
class ca(object): __slots__ = ("a",)
class cb(ca): __slots__ = ("a","b")
class cc(ca): __slots__ = ("a","c")
class cd(cb,cc): __slots__ = ("a","b","c","d")

in line "class cd(.." thorws a exception
TypeError: multiple bases have instance lay-out conflict

(if cb (or cc) doesn't define __slots__ it works.)

My only solution is to generate a "unsloted" class (_ca)
and genererate a "sloted" class (ca) with only the __slots__ attribute.
when i had to inherit the class i use the "unsloted" class.

like that:
class _ca(object): pass
class ca(object): __slots__ = ("a",)
class _cb(_ca): pass
class cb(_cb): __slots__ = ("a","b")
class _cc(_ca): pass
class cc(_cc): __slots__ = ("a","c")
class _cd(_cb,_cc): pass
class cd(_cd): __slots__ = ("a","b","c","d")

my source does this a metaclass

my question is is their a nicer way to do this?

More information about the Python-list mailing list