[Python-bugs-list] [ python-Bugs-723540 ] __slots__ broken in 2.3a with ("__dict__", )

SourceForge.net noreply@sourceforge.net
Fri, 18 Apr 2003 00:35:29 -0700


Bugs item #723540, was opened at 2003-04-18 02:35
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=723540&group_id=5470

Category: Type/class unification
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Douglas Napoleone (derivin)
Assigned to: Nobody/Anonymous (nobody)
Summary: __slots__ broken in 2.3a with ("__dict__", )

Initial Comment:
I LOVE using __slots__. I love using properties.
I made my own extension and metaclass so I could 
define type safe properties in classes. I could stick 
properties on a class and have them accessed 
seperatly from slots (because they are properties and 
not attributes). The properties call setter/getters and 
store the data in __dict__ (a cheezy means of making 
pickle still work with no effort). thus I had __slots__ = 
('__dict__', ) in my base class. this worked great in 2.2 
and 2.2.2.  Im migrating all my modules to 2.3. I just 
fixed a bug in my code that was due to a typo. Thats 
when I realized that __slots__ was no longer working in 
2.3a. I cant find anything on this change in behavior.

if slots contains "__dict__" slots is turned OFF!!!
simplified version of the bug:

$ python
Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more 
information.
>>> class foo(object):
...   __slots__ = ("__dict__", )
...
>>> a = foo()
>>> a.bad = 3
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'foo' object has no attribute 'bad'
>>> ^Z

$ python23
Python 2.3a2 (#39, Feb 19 2003, 17:58:58) [MSC 
v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more 
information.
>>> class foo(object):
...   __slots__ = ("__dict__", )
...
>>> a = foo()
>>> a.bad = 3
>>> dir(a)
['__class__', '__delattr__', '__dict__', '__doc__', '__getattr
ibute__', '__hash_
_', '__init__', '__module__', '__new__', '__reduce__', '__re
duce_ex__', '__repr_
_', '__setattr__', '__slots__', '__str__', 'bad']
>>> ^Z



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=723540&group_id=5470