Skip to content

Commit

Permalink
Merge r71222 from old branch:
Browse files Browse the repository at this point in the history
  Allow assignment to a wrapper's __parent__.
  • Loading branch information
philikon committed Jul 10, 2007
1 parent 3ce7f69 commit 062b381
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions _Acquisition.c
Expand Up @@ -627,8 +627,8 @@ Wrapper_setattro(Wrapper *self, PyObject *oname, PyObject *v)

/* Allow assignment to parent, to change context. */
if (PyString_Check(oname)) name=PyString_AS_STRING(oname);
if (*name=='a' && name[1]=='q' && name[2]=='_'
&& strcmp(name+3,"parent")==0)
if ((*name=='a' && name[1]=='q' && name[2]=='_'
&& strcmp(name+3,"parent")==0) || (strcmp(name, "__parent__")==0))
{
Py_XINCREF(v);
ASSIGN(self->container, v);
Expand Down
16 changes: 15 additions & 1 deletion tests.py
Expand Up @@ -1401,14 +1401,28 @@ def test_creating_wrappers_directly():
...
TypeError: __init__() takes exactly 2 arguments (1 given)
We can reassign aq_parent
We can reassign aq_parent / __parent__ on a wrapper:
>>> x = B()
>>> x.color = 'green'
>>> w.aq_parent = x
>>> w.color
'green'
>>> y = B()
>>> y.color = 'blue'
>>> w.__parent__ = y
>>> w.color
'blue'
Note that messing with the wrapper won't in any way affect the
wrapped object:
>>> Acquisition.aq_base(w).__parent__
Traceback (most recent call last):
...
AttributeError: __parent__
>>> w = ImplicitAcquisitionWrapper()
Traceback (most recent call last):
...
Expand Down

0 comments on commit 062b381

Please sign in to comment.