From d693a81595ae3c617f5dd20f9a8bf8b7f130683b Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 30 Jun 2003 04:18:48 +0000 Subject: [PATCH] Fix SF 762891: "del p[key]" on proxy object raises SystemError() --- Lib/test/test_weakref.py | 11 +++++++++++ Misc/NEWS | 33 +++++++++++++++++++++++++++++++++ Objects/weakrefobject.c | 6 +++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index 5969f3552a5..1b450a364a2 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -226,6 +226,17 @@ class ReferencesTestCase(TestBase): self.assert_(not hasattr(o, 'foo'), "object does not reflect attribute removal via proxy") + def test_proxy_deletion(self): + # Test clearing of SF bug #762891 + class Foo: + result = None + def __delitem__(self, accessor): + self.result = accessor + g = Foo() + f = weakref.proxy(g) + del f[0] + self.assertEqual(f.result, 0) + def test_getweakrefcount(self): o = C() ref1 = weakref.ref(o) diff --git a/Misc/NEWS b/Misc/NEWS index dbd919206b0..022a1a6a757 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -4,6 +4,39 @@ Python News (editors: check NEWS.help for information about editing NEWS using ReST.) +What's New in Python 2.3 release candidate? +=========================================== + +Core and builtins +----------------- + +Extension modules +----------------- + +- weakref.proxy() can now handle "del obj[i]" for proxy objects + defining __delitem__. Formerly, it generated a SystemError. + +- SSL no longer crashes the interpreter when the remote side disconnects. + +Library +------- + +Tools/Demos +----------- + +Build +----- + +C API +----- + +Windows +------- + +Mac +--- + + What's New in Python 2.3 beta 2? ================================ diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index e26cb65b130..f5afb536277 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -389,7 +389,11 @@ proxy_setitem(PyWeakReference *proxy, PyObject *key, PyObject *value) { if (!proxy_checkref(proxy)) return -1; - return PyObject_SetItem(PyWeakref_GET_OBJECT(proxy), key, value); + + if (value == NULL) + return PyObject_DelItem(PyWeakref_GET_OBJECT(proxy), key); + else + return PyObject_SetItem(PyWeakref_GET_OBJECT(proxy), key, value); } /* iterator slots */