[Python-bugs-list] [ python-Bugs-612071 ] __slots__ ignored in derived classes
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 20 Sep 2002 04:18:41 -0700
Bugs item #612071, was opened at 2002-09-20 11:18
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=612071&group_id=5470
Category: Type/class unification
Group: Python 2.2.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Yakov Markovitch (markovitch)
Assigned to: Nobody/Anonymous (nobody)
Summary: __slots__ ignored in derived classes
Initial Comment:
If some class is based on another new-style class and
defines __slots__, and the base class has no __slots__
definition, __slots__ in derived class completely ignored.
E.g.:
class A(object):
pass
class B(A):
__slots__ = ['a']
b = B()
b.a = 1
b.b = 2
print b.a, b.b
The code above serenely prints
1 2
On the other hand,
class A(object):
__slots__ = []
class B(A):
__slots__ = ['a']
b = B()
b.a = 1
b.b = 2
print b.a, b.b
raises AttributeError:
AttributeError: 'B' object has no attribute 'b'
which is correct.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=612071&group_id=5470