[pypy-svn] r67498 - in pypy/trunk/pypy/rlib: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Fri Sep 4 18:51:44 CEST 2009
Author: cfbolz
Date: Fri Sep 4 18:51:43 2009
New Revision: 67498
Modified:
pypy/trunk/pypy/rlib/rweakref.py
pypy/trunk/pypy/rlib/test/test_rweakref.py
Log:
Need a union of SomeWeakValueDict
Modified: pypy/trunk/pypy/rlib/rweakref.py
==============================================================================
--- pypy/trunk/pypy/rlib/rweakref.py (original)
+++ pypy/trunk/pypy/rlib/rweakref.py Fri Sep 4 18:51:43 2009
@@ -3,6 +3,7 @@
and a limited version of WeakValueDictionary. LLType only for now!
"""
+from pypy.tool.pairtype import pairtype
import weakref
from weakref import ref
@@ -54,6 +55,13 @@
s_oldvalue = self.method_get(s_key)
assert s_oldvalue.contains(s_value)
+class __extend__(pairtype(SomeWeakValueDict, SomeWeakValueDict)):
+ def union((s_wvd1, s_wvd2)):
+ basedef = s_wvd1.valueclassdef.commonbase(s_wvd2.valueclassdef)
+ if basedef is None: # no common base class! complain...
+ return SomeObject()
+ return SomeWeakValueDict(basedef)
+
class Entry(extregistry.ExtRegistryEntry):
_about_ = RWeakValueDictionary
Modified: pypy/trunk/pypy/rlib/test/test_rweakref.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_rweakref.py (original)
+++ pypy/trunk/pypy/rlib/test/test_rweakref.py Fri Sep 4 18:51:43 2009
@@ -86,3 +86,24 @@
#
f()
interpret(f, [])
+
+
+def test_rpython_merge_RWeakValueDictionary():
+ class A(object):
+ def __init__(self):
+ self.d = RWeakValueDictionary(A)
+ def f(self, key):
+ a = A()
+ self.d.set(key, a)
+ return a
+ empty = A()
+ def f(x):
+ a = A()
+ if x:
+ a = empty
+ a2 = a.f("a")
+ assert a.d.get("a") is a2
+ f(0)
+ interpret(f, [0])
+ f(1)
+ interpret(f, [1])
More information about the Pypy-commit
mailing list