summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2015-01-30 18:33:42 (GMT)
committerBenjamin Peterson <benjamin@python.org>2015-01-30 18:33:42 (GMT)
commit9d4cbcc86bbef64ec00ba4987b5fc35e3a5f433d (patch)
tree790823b6da6784389d4f3062a36cc09b3bc0e31a /Lib
parent91496a08d4cb0b185fed53692cd9f36c76de9725 (diff)
downloadcpython-9d4cbcc86bbef64ec00ba4987b5fc35e3a5f433d.zip
cpython-9d4cbcc86bbef64ec00ba4987b5fc35e3a5f433d.tar.gz
cpython-9d4cbcc86bbef64ec00ba4987b5fc35e3a5f433d.tar.bz2
allow changing __class__ between a heaptype and non-heaptype in some cases (closes #22986)
Patch by Nathaniel Smith.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_descr.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 0c88fd2..595af4b 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1026,6 +1026,22 @@ order (MRO) for bases """
self.assertEqual(x.foo, 1)
self.assertEqual(x.__dict__, {'foo': 1})
+ def test_object_class_assignment_between_heaptypes_and_nonheaptypes(self):
+ class SubType(types.ModuleType):
+ a = 1
+
+ m = types.ModuleType("m")
+ self.assertTrue(m.__class__ is types.ModuleType)
+ self.assertFalse(hasattr(m, "a"))
+
+ m.__class__ = SubType
+ self.assertTrue(m.__class__ is SubType)
+ self.assertTrue(hasattr(m, "a"))
+
+ m.__class__ = types.ModuleType
+ self.assertTrue(m.__class__ is types.ModuleType)
+ self.assertFalse(hasattr(m, "a"))
+
def test_slots(self):
# Testing __slots__...
class C0(object):