[pypy-svn] r79872 - in pypy/branch/fast-forward/pypy/module/_weakref: . test
afa at codespeak.net
afa at codespeak.net
Tue Dec 7 18:11:05 CET 2010
Author: afa
Date: Tue Dec 7 18:11:03 2010
New Revision: 79872
Modified:
pypy/branch/fast-forward/pypy/module/_weakref/interp__weakref.py
pypy/branch/fast-forward/pypy/module/_weakref/test/test_weakref.py
Log:
weakref.ref accepts additional keyword arguments, but no extra positional arguments.
Modified: pypy/branch/fast-forward/pypy/module/_weakref/interp__weakref.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_weakref/interp__weakref.py (original)
+++ pypy/branch/fast-forward/pypy/module/_weakref/interp__weakref.py Tue Dec 7 18:11:03 2010
@@ -144,12 +144,21 @@
def descr__new__weakref(space, w_subtype, w_obj, w_callable=None,
__args__=None):
+ if __args__.arguments_w:
+ raise OperationError(space.w_TypeError, space.wrap(
+ "__new__ expected at most 2 arguments"))
lifeline = w_obj.getweakref()
if lifeline is None:
lifeline = WeakrefLifeline(space)
w_obj.setweakref(space, lifeline)
return lifeline.get_or_make_weakref(space, w_subtype, w_obj, w_callable)
+def descr__init__weakref(space, self, w_obj, w_callable=None,
+ __args__=None):
+ if __args__.arguments_w:
+ raise OperationError(space.w_TypeError, space.wrap(
+ "__init__ expected at most 2 arguments"))
+
def descr__eq__(space, ref1, w_ref2):
if not isinstance(w_ref2, W_Weakref):
return space.w_NotImplemented
@@ -186,6 +195,9 @@
__new__ = interp2app(descr__new__weakref,
unwrap_spec=[ObjSpace, W_Root, W_Root, W_Root,
Arguments]),
+ __init__ = interp2app(descr__init__weakref,
+ unwrap_spec=[ObjSpace, W_Weakref, W_Root, W_Root,
+ Arguments]),
__eq__ = interp2app(descr__eq__,
unwrap_spec=[ObjSpace, W_Weakref, W_Root]),
__ne__ = interp2app(descr__ne__,
Modified: pypy/branch/fast-forward/pypy/module/_weakref/test/test_weakref.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_weakref/test/test_weakref.py (original)
+++ pypy/branch/fast-forward/pypy/module/_weakref/test/test_weakref.py Tue Dec 7 18:11:03 2010
@@ -423,3 +423,13 @@
del a1
gc.collect()
assert ref1() is None
+
+ def test_init(self):
+ import _weakref, gc
+ # Issue 3634
+ # <weakref to class>.__init__() doesn't check errors correctly
+ r = _weakref.ref(Exception)
+ raises(TypeError, r.__init__, 0, 0, 0, 0, 0)
+ # No exception should be raised here
+ gc.collect()
+
More information about the Pypy-commit
mailing list