[Python-Dev] Change in evaluation order in new object model

M.-A. Lemburg mal@lemburg.com
Fri, 02 Nov 2001 17:22:34 +0100


Michael McLay wrote:
> 
> I was suprised by a change to the order of evaluation of members in the new
> object type.  I haven't found an explanation for why the change was made.  I
> was comfortable with the way it worked.  Is there an advantage to the change?.
> 
> In the classic python model the interpreter looked in the instance dictionary
> and if the name wasn't there it looked in the class dictionary.  The
> following illustrates this evaluation order.
> ...
> 
> With the new slots mechanism the order has been reversed.  The class level
> dictionary is searched and then the slots are evaluated.
> 
> >>> class B(object):
>     __slots__ = ['a','b','c']
> 
> >>> b = B()
> >>> b.a = 4
> >>> b.a
> 4
> >>> B.a = 6
> >>> b.a
> 6
> >>> b.a = 8
> Traceback (most recent call last):
>   File "<pyshell#61>", line 1, in ?
>     b.a = 8
> AttributeError: 'B' object attribute 'a' is read-only

Could someone please first explain what these slots are used for 
in the first place :-? There must be some difference to standard
class attributes... which is probably also the reason for the
above behaviour (even though it does look like a bug to me).

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/