[pypy-svn] r68433 - in pypy/branch/improve-kwd-args/pypy/module/_weakref: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Oct 14 14:28:47 CEST 2009


Author: cfbolz
Date: Wed Oct 14 14:28:46 2009
New Revision: 68433

Modified:
   pypy/branch/improve-kwd-args/pypy/module/_weakref/interp__weakref.py
   pypy/branch/improve-kwd-args/pypy/module/_weakref/test/test_weakref.py
Log:
the strict argument requirements in the weakref module were a bad idea. use
half-official fishing instead.


Modified: pypy/branch/improve-kwd-args/pypy/module/_weakref/interp__weakref.py
==============================================================================
--- pypy/branch/improve-kwd-args/pypy/module/_weakref/interp__weakref.py	(original)
+++ pypy/branch/improve-kwd-args/pypy/module/_weakref/interp__weakref.py	Wed Oct 14 14:28:46 2009
@@ -143,7 +143,11 @@
         return w_obj
         
 
-def descr__new__weakref(space, w_subtype, w_obj, w_callable=None):
+def descr__new__weakref(space, w_subtype, w_obj, __args__):
+    if __args__.arguments_w:
+        w_callable = __args__.arguments_w[0]
+    else:
+        w_callable = space.w_None
     lifeline = w_obj.getweakref()
     if lifeline is None:
         lifeline = WeakrefLifeline(space)
@@ -184,7 +188,7 @@
 which is called with the weak reference as an argument when 'obj'
 is about to be finalized.""",
     __new__ = interp2app(descr__new__weakref,
-                         unwrap_spec=[ObjSpace, W_Root, W_Root, W_Root]),
+                         unwrap_spec=[ObjSpace, W_Root, W_Root, Arguments]),
     __eq__ = interp2app(descr__eq__,
                         unwrap_spec=[ObjSpace, W_Weakref, W_Root]),
     __ne__ = interp2app(descr__ne__,

Modified: pypy/branch/improve-kwd-args/pypy/module/_weakref/test/test_weakref.py
==============================================================================
--- pypy/branch/improve-kwd-args/pypy/module/_weakref/test/test_weakref.py	(original)
+++ pypy/branch/improve-kwd-args/pypy/module/_weakref/test/test_weakref.py	Wed Oct 14 14:28:46 2009
@@ -162,13 +162,16 @@
         class A(object):
             pass
         class Ref(_weakref.ref):
-            pass
+            def __init__(self, ob, callback=None, **other):
+                self.__dict__.update(other)
         def callable(ref):
             b.a = 42
         a = A()
         b = A()
         b.a = 1
-        w = Ref(a, callable)
+        w = Ref(a, callable, x=1, y=2)
+        assert w.x == 1
+        assert w.y == 2
         assert a.__weakref__ is w
         assert b.__weakref__ is None
         w1 = _weakref.ref(a)
@@ -408,12 +411,3 @@
 
         a = A()
         assert _weakref.ref(a) == a
-    
-    def test_strange_arguments(self):
-        import _weakref
-        class A(object):
-            pass
-
-        a = A()
-        raises(TypeError, _weakref.ref, a, lambda x: None, 3)
-        raises(TypeError, _weakref.ref, a, lambda x: None, b=3)



More information about the Pypy-commit mailing list