Fixed issue #2396 (support weak refs in Python)

This commit is contained in:
Matthias Koefferlein
2026-07-19 10:45:51 +02:00
parent 3c6b342448
commit 6253f04966
3 changed files with 25 additions and 0 deletions
+15
View File
@@ -22,6 +22,7 @@ import os
import sys
import gc
import copy
import weakref
# Set this to True to disable some tests involving exceptions
leak_check = "TEST_LEAK_CHECK" in os.environ
@@ -3352,6 +3353,20 @@ class BasicTest(unittest.TestCase):
self.assertEqual(bc.str(), "xyz")
self.assertEqual(bnc.str(), "xyz")
# weak refs
def test_94(self):
b = pya.B()
b.set_str("abc")
r = weakref.ref(b)
self.assertEqual(r() is None, False)
self.assertEqual(r().str(), "abc")
b = None
self.assertEqual(r() is None, True)
# run unit tests
if __name__ == '__main__':
suite = unittest.TestSuite()