]> granicus.if.org Git - python/commitdiff
SF bug #1770766: weakref proxy has incorrect __nonzero__ behavior.
authorRaymond Hettinger <python@rcn.com>
Sun, 27 Mar 2005 03:04:54 +0000 (03:04 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 27 Mar 2005 03:04:54 +0000 (03:04 +0000)
Lib/test/test_weakref.py
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 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