Add explicit ObjectProxy.__getattr__() in C implementation so can be called from derived classes.
This commit is contained in:
@@ -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
|
||||
-------------
|
||||
|
||||
|
||||
@@ -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 },
|
||||
};
|
||||
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user