Adding a method to an extension class changes its 'tp_getattro' behavior?
I'm trying to flesh out the 'zope.proxy' wrapper class to include methods defined in newer Python versions: in particular, in Python 2.6, the proxy's delegation to the wrapped object works without an explicit '__reduce__' on the wrapper, but new B&D code in Python 2.7 breaks that. So, I went to add '__reduced__' to the wrapper's methods, using the follwing patch: --------------------------- %< ------------------------ === modified file 'src/zope/proxy/_zope_proxy_proxy.c' --- src/zope/proxy/_zope_proxy_proxy.c 2012-06-06 01:29:23 +0000 +++ src/zope/proxy/_zope_proxy_proxy.c 2012-06-06 01:36:05 +0000 @@ -789,6 +789,17 @@ return NULL; } +static char +rvd_doc[] = +"__reversed__()\n" +"Return the reverse iterator for the wrapped object."; + +static PyObject * +wrap_reversed(PyObject *self) +{ + return PyReversed_New(Proxy_GET_OBJECT(self)); +} + static PyNumberMethods wrap_as_number = { wrap_add, /* nb_add */ @@ -872,6 +883,7 @@ static PyMethodDef wrap_methods[] = { {"__reduce__", (PyCFunction)wrap_reduce, METH_NOARGS, reduce__doc__}, + {"__reversed__", (PyCFunction)wrap_reversed, METH_NOARGS, rvd_doc}, {NULL, NULL}, }; --------------------------- %< ------------------------ The patched code compiles, and the unit test which failed under 2.7 now passs under both Python 2.6 and 2.7. However, the patched code now fails a new error under both 2.6 and 2.7: the breakage indicates that the wrapper's 'tp_getattro' implementation is now returning an attribute of the wrapper, where previously it returned the same-named attriute of the wrapped object. Can anyone suggest a reason why adding a method to the 'tp_methods' table would have such an effect? Tres. -- =================================================================== Tres Seaver +1 540-429-0999 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com
participants (1)
-
Tres Seaver