[Python-Dev] Explorations on new-style classes
David Abrahams
David Abrahams" <david.abrahams@rcn.com
Tue, 5 Mar 2002 17:22:14 -0500
----- Original Message -----
From: "Kevin Jacobs" <jacobs@penguin.theopalgroup.com>
> Second, I've been twisting metaclasses to do my evil bidding.
Fun, innit?
> In this case,
> I have implemented pseudo-typed attributes and slots in Python. e.g.:
>
> class A(object):
> __metaclass__ = ConstrainedObject
> __slots__ = {'a':int,'b':float}
Although I understand the appeal, using __slots__ to constrain the
attributes might be misguided (depending on your goals):
>>> class A(object):
... __slots__ = [ 'a' ]
...
>>> class B(object):
... __slots__ = [ 'b' ]
...
>>> class C(A,B): pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: multiple bases have instance lay-out conflict
>>> class D(object): pass
...
>>> class C(A,D): pass
...
>>>