]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
SF bug #1770766: weakref proxy has incorrect __nonzero__ behavior.
authorRaymond Hettinger <python@rcn.com>
Thu, 31 Mar 2005 04:07:55 +0000 (04:07 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 31 Mar 2005 04:07:55 +0000 (04:07 +0000)
Lib/test/test_weakref.py
Misc/NEWS
Objects/weakrefobject.c

index 75869a758a65ecd4675b86ff4b66fca772d0499e..2754cec5a2c1c838146f0263a5da5ccf7329da4b 100644 (file)
@@ -271,6 +271,12 @@ class ReferencesTestCase(TestBase):
         del f[0]
         self.assertEqual(f.result, 0)
 
+    def test_proxy_bool(self):
+        # Test clearing of SF bug #1170766
+        class List(list): pass
+        lyst = List()
+        self.assertEqual(bool(weakref.proxy(lyst)), bool(lyst))
+
     def test_getweakrefcount(self):
         o = C()
         ref1 = weakref.ref(o)
index 739f50fa4d7d14f145c110605f1de16f3fcd690e..1639709b97eb178c6bd5557bf91e52c0b1720d19 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -4,6 +4,15 @@ Python News
 
 (editors: check NEWS.help for information about editing NEWS using ReST.)
 
+What's New in Python 2.4.2a
+===========================
+
+Extension Modules
+-----------------
+
+- weakref proxy has incorrect __nonzero__ behavior.  SF bug #1770766.
+
+
 What's New in Python 2.4.1 final?
 =================================
 
index 02370c4a7ae805d2bf3ea172a0d341e876be0e9b..5412dd3172610e84355cabf0dea193da61c4fa21 100644 (file)
@@ -505,11 +505,7 @@ proxy_nonzero(PyWeakReference *proxy)
     PyObject *o = PyWeakref_GET_OBJECT(proxy);
     if (!proxy_checkref(proxy))
         return -1;
-    if (o->ob_type->tp_as_number &&
-        o->ob_type->tp_as_number->nb_nonzero)
-        return (*o->ob_type->tp_as_number->nb_nonzero)(o);
-    else
-        return 1;
+    return PyObject_IsTrue(o);
 }
 
 static void