summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_descr.py
diff options
context:
space:
mode:
authorŽiga Seilnacht <ziga.seilnacht@gmail.com>2007-03-16 11:59:38 (GMT)
committerŽiga Seilnacht <ziga.seilnacht@gmail.com>2007-03-16 11:59:38 (GMT)
commit6f2d09c949ac0c21c56c97e7f772a2726e34d74f (patch)
treee7244ea4d06e42bc6fd8f1745bed0ce682947c5f /Lib/test/test_descr.py
parent6ab8452036beead2b74d38564162b291f2db643c (diff)
downloadcpython-6f2d09c949ac0c21c56c97e7f772a2726e34d74f.zip
cpython-6f2d09c949ac0c21c56c97e7f772a2726e34d74f.tar.gz
cpython-6f2d09c949ac0c21c56c97e7f772a2726e34d74f.tar.bz2
Patch #1623563: allow __class__ assignment for classes with __slots__.
The old and the new class are still required to have the same slot names, but the order in which they are specified is not relevant.
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r--Lib/test/test_descr.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 71f4ec4..5abecf4 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -2853,6 +2853,51 @@ def setclass():
cant(o, type(1))
cant(o, type(None))
del o
+ class G(object):
+ __slots__ = ["a", "b"]
+ class H(object):
+ __slots__ = ["b", "a"]
+ try:
+ unicode
+ except NameError:
+ class I(object):
+ __slots__ = ["a", "b"]
+ else:
+ class I(object):
+ __slots__ = [unicode("a"), unicode("b")]
+ class J(object):
+ __slots__ = ["c", "b"]
+ class K(object):
+ __slots__ = ["a", "b", "d"]
+ class L(H):
+ __slots__ = ["e"]
+ class M(I):
+ __slots__ = ["e"]
+ class N(J):
+ __slots__ = ["__weakref__"]
+ class P(J):
+ __slots__ = ["__dict__"]
+ class Q(J):
+ pass
+ class R(J):
+ __slots__ = ["__dict__", "__weakref__"]
+
+ for cls, cls2 in ((G, H), (G, I), (I, H), (Q, R), (R, Q)):
+ x = cls()
+ x.a = 1
+ x.__class__ = cls2
+ verify(x.__class__ is cls2,
+ "assigning %r as __class__ for %r silently failed" % (cls2, x))
+ vereq(x.a, 1)
+ x.__class__ = cls
+ verify(x.__class__ is cls,
+ "assigning %r as __class__ for %r silently failed" % (cls, x))
+ vereq(x.a, 1)
+ for cls in G, J, K, L, M, N, P, R, list, Int:
+ for cls2 in G, J, K, L, M, N, P, R, list, Int:
+ if cls is cls2:
+ continue
+ cant(cls(), cls2)
def setdict():
if verbose: print "Testing __dict__ assignment..."