[ python-Bugs-1170766 ] weakref.proxy incorrect behaviour
SourceForge.net
noreply at sourceforge.net
Sun Mar 27 13:17:02 CEST 2005
Bugs item #1170766, was opened at 2005-03-25 16:54
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1170766&group_id=5470
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Alexander Kozlovsky (kozlovsky)
Assigned to: Nobody/Anonymous (nobody)
Summary: weakref.proxy incorrect behaviour
Initial Comment:
According documentation, proxy in most contexts must
have the same behaviour as object itself.
PROBLEM:
bool(proxy_object) != bool(object_itself)
EXAMPLE:
>>> class X(list): pass # collection class
...
>>> x = X() # empty collection
>>> import weakref
>>> proxy = weakref.proxy(x)
>>> bool(x)
False
>>> bool(proxy)
True
PYTHON VERSION:
2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit
(Intel)]
also tested on:
2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit
(Intel)]
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2005-03-27 06:17
Message:
Logged In: YES
user_id=80475
Fixed the __nonzero__ problem for Py2.5 and will backport to
Py2.4. See Objects/weakrefobject.c 1.21.
Leaviing this report open until the rest of the module can
be checked and fixed.
----------------------------------------------------------------------
Comment By: Armin Rigo (arigo)
Date: 2005-03-26 09:50
Message:
Logged In: YES
user_id=4771
The bug is in weakrefobject:proxy_nonzero(), which calls the underlying object's nb_nonzero slot instead of going through the general PyObject_IsTrue() mecanism. Built-in types like list and dict don't have a nb_nonzero slot.
As a related bug, (Callable)ProxyType should implement tp_richcompare in addition to tp_compare. In fact, we should review the code to check if ProxyType knows about the most recent type slots...
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1170766&group_id=5470
More information about the Python-bugs-list
mailing list