Bugs item #1170766, was opened at 2005-03-25 16:54 Message generated for change (Settings changed) 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: 6 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: Michael Hudson (mwh) Date: 2005-03-29 08:39 Message: Logged In: YES user_id=6656 Also see bug #1075356 (which is very minor, but might as well get fixed at the same time). ---------------------------------------------------------------------- Comment By: Armin Rigo (arigo) Date: 2005-03-29 08:23 Message: Logged In: YES user_id=4771 The following type slots appear to be missing in the proxy types: * nb_(inplace_){floor,true}_divide * sq_repeat, sq_concat, sq_item, sq_ass_item, sq_inplace_concat, sq_inplace_repeat (which are needed for operator.repeat(), operator.concat(), etc. to work) * tp_as_buffer * tp_richcompare (tp_compare alone is not enough) * tp_descr_get, tp_descr_set (for proxies to descriptors...) * nb_coerce (though it seems that only an explicit call to coerce() can show that this is missing; implicit coercion is done correctly in other operators) * nb_oct, nb_hex As far as I can tell, there is no existing operator that is broken in the same way that nb_nonzero was. ---------------------------------------------------------------------- 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 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com