Commit e6c470f2 authored by Raymond Hettinger's avatar Raymond Hettinger

SF bug #1770766: weakref proxy has incorrect __nonzero__ behavior.

parent ca5d8fea
...@@ -271,6 +271,12 @@ class ReferencesTestCase(TestBase): ...@@ -271,6 +271,12 @@ class ReferencesTestCase(TestBase):
del f[0] del f[0]
self.assertEqual(f.result, 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): def test_getweakrefcount(self):
o = C() o = C()
ref1 = weakref.ref(o) ref1 = weakref.ref(o)
......
...@@ -505,11 +505,7 @@ proxy_nonzero(PyWeakReference *proxy) ...@@ -505,11 +505,7 @@ proxy_nonzero(PyWeakReference *proxy)
PyObject *o = PyWeakref_GET_OBJECT(proxy); PyObject *o = PyWeakref_GET_OBJECT(proxy);
if (!proxy_checkref(proxy)) if (!proxy_checkref(proxy))
return -1; return -1;
if (o->ob_type->tp_as_number && return PyObject_IsTrue(o);
o->ob_type->tp_as_number->nb_nonzero)
return (*o->ob_type->tp_as_number->nb_nonzero)(o);
else
return 1;
} }
static void static void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment