From 4cf27049b68a2c1dca643638f319966ba3fae4ee Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 31 Mar 2005 04:07:55 +0000 Subject: SF bug #1770766: weakref proxy has incorrect __nonzero__ behavior. --- Lib/test/test_weakref.py | 6 ++++++ Misc/NEWS | 9 +++++++++ Objects/weakrefobject.c | 6 +----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index 75869a7..2754cec 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index 739f50f..1639709 100644 --- 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? ================================= diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index 02370c4..5412dd3 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -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 -- cgit v0.12