[pypy-svn] r26463 - in pypy/dist/pypy/module/_weakref: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Apr 27 22:11:06 CEST 2006
Author: cfbolz
Date: Thu Apr 27 22:11:00 2006
New Revision: 26463
Modified:
pypy/dist/pypy/module/_weakref/interp__weakref.py
pypy/dist/pypy/module/_weakref/test/test_weakref.py
Log:
prevent direct creation of instances
Modified: pypy/dist/pypy/module/_weakref/interp__weakref.py
==============================================================================
--- pypy/dist/pypy/module/_weakref/interp__weakref.py (original)
+++ pypy/dist/pypy/module/_weakref/interp__weakref.py Thu Apr 27 22:11:00 2006
@@ -159,10 +159,15 @@
return w_obj.__lifeline__.get_proxy(space, w_obj, w_callable)
def descr__new__proxy(space, w_subtype, w_obj, w_callable=None):
- assert isinstance(w_obj, W_Weakrefable)
- if w_obj.__lifeline__ is None:
- w_obj.__lifeline__ = WeakrefLifeline()
- return w_obj.__lifeline__.get_proxy(space, w_subtype, w_obj, w_callable)
+ raise OperationError(
+ space.w_TypeError,
+ space.wrap("cannot create 'weakproxy' instances"))
+
+def descr__new__callableproxy(space, w_subtype, w_obj, w_callable=None):
+ raise OperationError(
+ space.w_TypeError,
+ space.wrap("cannot create 'weakcallableproxy' instances"))
+
def force(space, proxy):
if not isinstance(proxy, W_Proxy):
@@ -199,8 +204,8 @@
**proxy_typedef_dict)
W_Proxy.typedef.accepable_as_base_class = False
-W_CallableProxy.typedef = TypeDef("callableweakproxy",
- __new__ = interp2app(descr__new__proxy),
+W_CallableProxy.typedef = TypeDef("weakcallableproxy",
+ __new__ = interp2app(descr__new__callableproxy),
__call__ = interp2app(W_CallableProxy.descr__call__,
unwrap_spec=['self', ObjSpace, Arguments]),
**callable_proxy_typedef_dict)
Modified: pypy/dist/pypy/module/_weakref/test/test_weakref.py
==============================================================================
--- pypy/dist/pypy/module/_weakref/test/test_weakref.py (original)
+++ pypy/dist/pypy/module/_weakref/test/test_weakref.py Thu Apr 27 22:11:00 2006
@@ -153,3 +153,9 @@
a_ = _weakref.proxy(a)
a_()
assert global_a.x == 1
+
+ def test_dont_create_directly(self):
+ import _weakref
+ raises(TypeError, _weakref.ProxyType, [])
+ raises(TypeError, _weakref.CallableProxyType, [])
+
More information about the Pypy-commit
mailing list