mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
[3.13] GH-124547: Clear instance dictionary if memory error occurs during object dealloc (GH-124627) (#124714)
GH-124547: Clear instance dictionary if memory error occurs during object dealloc (GH-124627)
(cherry picked from commit 0e21cc6cf8
)
Co-authored-by: Mark Shannon <mark@hotpy.org>
This commit is contained in:
parent
0a125d9029
commit
80de9766f7
3 changed files with 27 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
"Test the functionality of Python classes implementing operators."
|
||||
|
||||
import unittest
|
||||
import test.support
|
||||
|
||||
testmeths = [
|
||||
|
||||
|
@ -919,6 +920,20 @@ class TestInlineValues(unittest.TestCase):
|
|||
C.a = X()
|
||||
C.a = X()
|
||||
|
||||
def test_detach_materialized_dict_no_memory(self):
|
||||
import _testcapi
|
||||
class A:
|
||||
def __init__(self):
|
||||
self.a = 1
|
||||
self.b = 2
|
||||
a = A()
|
||||
d = a.__dict__
|
||||
with test.support.catch_unraisable_exception() as ex:
|
||||
_testcapi.set_nomemory(0, 1)
|
||||
del a
|
||||
self.assertEqual(ex.unraisable.exc_type, MemoryError)
|
||||
with self.assertRaises(KeyError):
|
||||
d["a"]
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue