zopefoundation/zope.container — pull request #3 by jamadden (2014-02-20 00:15:58+00:00)
Title: Support PyPy with a pure-Python version of ContainedProxy

Based on the code in `zope.proxy`, this PR provides a Python implementation of `ContainedProxyBase` and uses it on PyPy. Note that to use/test it, you must have the recent changes merged into `persistent` and `ZODB`, but with those changes, all the test cases, with one exception, for this project pass under PyPy for me. (If you don't have those changes, you get strange exceptions running the ZODB-based tests.) As far as I can tell, these objects even pickle the same way as the C-based object does so compatibility at the ZODB/pickle level should be possible (but maybe that needs a more explicit test of some sort?)

Why not just use the Python proxy already defined in `zope.proxy`? Unfortunately, due to the use of `__slots__` in both `persistent.persistence.Persistent` and `zope.proxy.PyProxyBase`, it's not possible to have them both as a superclass due to instance layout conflicts.

The one test failure is in `test_contained_zodb:test_proxy_cache_interactions`: The example testing that after GC of the picklecache the contained object is now a ghost:

But it's a ghost:

>>> conn.root()['p']._p_changed

actually prints `False` there instead of `None`. I wasn't sure what to do about that, if it might be due to the different strategy of GC in the Python picklecache, and I wasn't sure whether it was important or not.

I'm sure this is rough, feedback and comments welcome!