summaryrefslogtreecommitdiff
path: root/Lib/test/test_weakref.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_weakref.py')
-rw-r--r--Lib/test/test_weakref.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index e14df9ea08..228bc17b23 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -391,6 +391,26 @@ class ReferencesTestCase(TestBase):
lyst = List()
self.assertEqual(bool(weakref.proxy(lyst)), bool(lyst))
+ def test_proxy_iter(self):
+ # Test fails with a debug build of the interpreter
+ # (see bpo-38395).
+
+ obj = None
+
+ class MyObj:
+ def __iter__(self):
+ nonlocal obj
+ del obj
+ return NotImplemented
+
+ obj = MyObj()
+ p = weakref.proxy(obj)
+ with self.assertRaises(TypeError):
+ # "blech" in p calls MyObj.__iter__ through the proxy,
+ # without keeping a reference to the real object, so it
+ # can be killed in the middle of the call
+ "blech" in p
+
def test_getweakrefcount(self):
o = C()
ref1 = weakref.ref(o)