Add explicit ObjectProxy.__getattr__() in C implementation so can be called from derived classes.

This commit is contained in:
Graham Dumpleton
2013-10-02 10:29:01 +10:00
parent c7051eb94a
commit 4a6eac2e55
3 changed files with 41 additions and 0 deletions

View File

@@ -1,6 +1,16 @@
Changes
=======
Version 1.2.0
-------------
**Bugs Fixed**
* When creating a custom proxy by deriving from ObjectProxy and the custom
proxy needed to override __getattr__(), it was not possible to called the
base class ObjectProxy.__getattr__() when the C implementation of
ObjectProxy was being used.
Version 1.1.3
-------------

View File

@@ -1181,6 +1181,24 @@ static PyObject *WraptObjectProxy_getattro(
/* ------------------------------------------------------------------------- */
static PyObject *WraptObjectProxy_getattr(
WraptObjectProxyObject *self, PyObject *args)
{
PyObject *name = NULL;
#if PY_MAJOR_VERSION >= 3
if (!PyArg_ParseTuple(args, "U:__getattr__", &name))
return NULL;
#else
if (!PyArg_ParseTuple(args, "S:__getattr__", &name))
return NULL;
#endif
return WraptObjectProxy_getattro(self, name);
}
/* ------------------------------------------------------------------------- */
static int WraptObjectProxy_setattro(
WraptObjectProxyObject *self, PyObject *name, PyObject *value)
{
@@ -1338,6 +1356,8 @@ static PyMethodDef WraptObjectProxy_methods[] = {
METH_VARARGS | METH_KEYWORDS, 0 },
{ "__exit__", (PyCFunction)WraptObjectProxy_exit,
METH_VARARGS | METH_KEYWORDS, 0 },
{ "__getattr__", (PyCFunction)WraptObjectProxy_getattr,
METH_VARARGS , 0 },
{ NULL, NULL },
};

View File

@@ -1292,6 +1292,17 @@ class TestDerivedClassCreation(unittest.TestCase):
class DerivedClassAttributes(unittest.TestCase):
def test_attr_functions(self):
def function():
pass
proxy = wrapt.ObjectProxy(function)
self.assertTrue(hasattr(proxy, '__getattr__'))
self.assertTrue(hasattr(proxy, '__setattr__'))
self.assertTrue(hasattr(proxy, '__delattr__'))
def test_setup_class_attributes(self):
def function():