summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_descr.py
diff options
context:
space:
mode:
authorXiang Zhang <angwerzx@126.com>2017-03-08 03:18:49 (GMT)
committerGitHub <noreply@github.com>2017-03-08 03:18:49 (GMT)
commitc393ee858932f79bd6dabf31550f9a53ea90bc68 (patch)
treecd731aaacc73568a0781efab63ceef9e629bb0eb /Lib/test/test_descr.py
parentd5d3249e8a37936d32266fa06ac20017307a1f70 (diff)
downloadcpython-c393ee858932f79bd6dabf31550f9a53ea90bc68.zip
cpython-c393ee858932f79bd6dabf31550f9a53ea90bc68.tar.gz
cpython-c393ee858932f79bd6dabf31550f9a53ea90bc68.tar.bz2
bpo-24329: allow __qualname__ and __classcell__ in __slots__ (GH-495)
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r--Lib/test/test_descr.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 5da7ae5..92553e3 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1322,6 +1322,46 @@ order (MRO) for bases """
a.foo = 42
self.assertEqual(a.__dict__, {"foo": 42})
+ def test_slots_special2(self):
+ # Testing __qualname__ and __classcell__ in __slots__
+ class Meta(type):
+ def __new__(cls, name, bases, namespace, attr):
+ self.assertIn(attr, namespace)
+ return super().__new__(cls, name, bases, namespace)
+
+ class C1:
+ def __init__(self):
+ self.b = 42
+ class C2(C1, metaclass=Meta, attr="__classcell__"):
+ __slots__ = ["__classcell__"]
+ def __init__(self):
+ super().__init__()
+ self.assertIsInstance(C2.__dict__["__classcell__"],
+ types.MemberDescriptorType)
+ c = C2()
+ self.assertEqual(c.b, 42)
+ self.assertNotHasAttr(c, "__classcell__")
+ c.__classcell__ = 42
+ self.assertEqual(c.__classcell__, 42)
+ with self.assertRaises(TypeError):
+ class C3:
+ __classcell__ = 42
+ __slots__ = ["__classcell__"]
+
+ class Q1(metaclass=Meta, attr="__qualname__"):
+ __slots__ = ["__qualname__"]
+ self.assertEqual(Q1.__qualname__, C1.__qualname__[:-2] + "Q1")
+ self.assertIsInstance(Q1.__dict__["__qualname__"],
+ types.MemberDescriptorType)
+ q = Q1()
+ self.assertNotHasAttr(q, "__qualname__")
+ q.__qualname__ = "q"
+ self.assertEqual(q.__qualname__, "q")
+ with self.assertRaises(TypeError):
+ class Q2:
+ __qualname__ = object()
+ __slots__ = ["__qualname__"]
+
def test_slots_descriptor(self):
# Issue2115: slot descriptors did not correctly check
# the type of the given object