mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
allow changing __class__ between a heaptype and non-heaptype in some cases (closes #22986)
Patch by Nathaniel Smith.
This commit is contained in:
parent
91496a08d4
commit
9d4cbcc86b
3 changed files with 56 additions and 26 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue