]> granicus.if.org Git - python/commitdiff
Fix SF 762891: "del p[key]" on proxy object raises SystemError()
authorRaymond Hettinger <python@rcn.com>
Mon, 30 Jun 2003 04:18:48 +0000 (04:18 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 30 Jun 2003 04:18:48 +0000 (04:18 +0000)
Lib/test/test_weakref.py
Misc/NEWS
Objects/weakrefobject.c

index 5969f3552a56da1246030c83622196c0db99bbd3..1b450a364a256566e9f429f7dd3d4838c17ef426 100644 (file)
@@ -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)
index dbd919206b0397fb3a634c03aa66126a692d4340..022a1a6a757d53f59287e01229a9f041fe07a03b 100644 (file)
--- 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?
 ================================
 
index e26cb65b13041c4916c7cc0394e14f0de509fe57..f5afb53627734fe530c9d1fb07aa1082ca0bc3e0 100644 (file)
@@ -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 */