mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-121860: Fix crash when materializing managed dict (#121866)
The object's inline values may be marked invalid if the materialized dict was already initialized and then deleted.
This commit is contained in:
parent
c46d64e0ef
commit
162b41f577
3 changed files with 31 additions and 5 deletions
|
@ -882,6 +882,24 @@ class TestInlineValues(unittest.TestCase):
|
|||
f.a = 3
|
||||
self.assertEqual(f.a, 3)
|
||||
|
||||
def test_rematerialize_object_dict(self):
|
||||
# gh-121860: rematerializing an object's managed dictionary after it
|
||||
# had been deleted caused a crash.
|
||||
class Foo: pass
|
||||
f = Foo()
|
||||
f.__dict__["attr"] = 1
|
||||
del f.__dict__
|
||||
|
||||
# Using a str subclass is a way to trigger the re-materialization
|
||||
class StrSubclass(str): pass
|
||||
self.assertFalse(hasattr(f, StrSubclass("attr")))
|
||||
|
||||
# Changing the __class__ also triggers the re-materialization
|
||||
class Bar: pass
|
||||
f.__class__ = Bar
|
||||
self.assertIsInstance(f, Bar)
|
||||
self.assertEqual(f.__dict__, {})
|
||||
|
||||
def test_store_attr_type_cache(self):
|
||||
"""Verifies that the type cache doesn't provide a value which is
|
||||
inconsistent from the dict."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue