PEP idea. ( removing __slots__ )

simon place simon_place at whsmithnet.co.uk
Sun Jul 6 17:42:11 EDT 2003


> No. Some classes have slots for efficiency, and their subclasses have
> dictionaries for generality.
> 
> Likewise, some classes have slots to save the dictionary for most
> instances, but some instances may need additional attributes, in which
> case Python creates the dictionary on-the-fly.

I know subclasses can add a __dict__, but i really thought a class with 
__slots__ could not have a __dict__, doesn't the script below show this 
behavior?


PythonWin 2.3b2 (#43, Jun 29 2003, 16:43:04) [MSC v.1200 32 bit (Intel)] 
on win32.
Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - 
see 'Help/About PythonWin' for further copyright information.
 >>> class A(object):
... 	__slots__=['a']
... 	
 >>> b=A()
 >>> b
<__main__.A object at 0x00EFABF0>
 >>> b.__dict__
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
AttributeError: 'A' object has no attribute '__dict__'
 >>> b.a
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
AttributeError: a
 >>> b.a=1
 >>> b.a
1
 >>> b.b=1
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
AttributeError: 'A' object has no attribute 'b'
 >>>





More information about the Python-list mailing list