Skip to content

Commit 0600aa7

Browse files
committed
Check the old dict after clearing it
1 parent 3fd3f1e commit 0600aa7

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

‎Lib/test/test_capi/test_dict.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ class A: ...
640640
a = A()
641641
a.x = 1
642642
f = as_frozendict(a.__dict__)
643+
self.assertEqual(vars(a), {})
643644
a.x = 2
644645
self.assertEqual(f, frozendict(x=1))
645646
self.assertEqual(vars(a), {'x': 2})

‎Objects/dictobject.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8696,9 +8696,11 @@ transfer_keys_and_values_lock_held(PyObject *res, PyObject *dict)
86968696
clear_common(old);
86978697
set_keys(old, Py_EMPTY_KEYS);
86988698
set_values(old, NULL);
8699-
ASSERT_CONSISTENT(old);
87008699
}
8700+
ASSERT_CONSISTENT(old);
87018701

8702+
// Only transfer keys and values to the new dict
8703+
// once the old dict is cleared
87028704
new->ma_used = used;
87038705
new->ma_keys = keys;
87048706
new->ma_values = values;

0 commit comments

Comments
 (0)