Skip to content

Commit 671d3f7

Browse files
committed
Add a test case.
1 parent e3cafb7 commit 671d3f7

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lib/test/test_dict.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,26 @@ def make_pairs():
14861486
self.assertEqual(d.get(key3_3), 44)
14871487
self.assertGreaterEqual(eq_count, 1)
14881488

1489+
def test_overwrite_managed_dict(self):
1490+
# GH-130327: Overwriting an object's managed dict incorrectly stored
1491+
# the new dictionary in the managed dict pointer for objects supporting
1492+
# inline values, leading to early clearing of the dictionary
1493+
import gc
1494+
1495+
class Shenanigans:
1496+
pass
1497+
1498+
to_be_deleted = Shenanigans()
1499+
to_be_deleted.attr = "whatever"
1500+
holds_reference = Shenanigans()
1501+
holds_reference.__dict__ = to_be_deleted.__dict__
1502+
holds_reference.ref = {"circular": to_be_deleted, "data": 42}
1503+
1504+
del to_be_deleted
1505+
gc.collect()
1506+
self.assertEqual(holds_reference.ref['data'], 42)
1507+
self.assertEqual(holds_reference.attr, "whatever")
1508+
14891509

14901510
class CAPITest(unittest.TestCase):
14911511

0 commit comments

Comments
 (0)