[pypy-svn] r62139 - in pypy/trunk/pypy: config objspace/std objspace/std/test
cfbolz at codespeak.net
cfbolz at codespeak.net
Wed Feb 25 14:40:31 CET 2009
Author: cfbolz
Date: Wed Feb 25 14:40:31 2009
New Revision: 62139
Modified:
pypy/trunk/pypy/config/pypyoption.py
pypy/trunk/pypy/objspace/std/test/test_typeobject.py
pypy/trunk/pypy/objspace/std/typeobject.py
Log:
Make it possible with a translation-time option to make Python builtin-types
mutable.
Modified: pypy/trunk/pypy/config/pypyoption.py
==============================================================================
--- pypy/trunk/pypy/config/pypyoption.py (original)
+++ pypy/trunk/pypy/config/pypyoption.py Wed Feb 25 14:40:31 2009
@@ -323,6 +323,8 @@
ChoiceOption("multimethods", "the multimethod implementation to use",
["doubledispatch", "mrd"],
default="mrd"),
+ BoolOption("immutable_builtintypes",
+ "Forbid the changing of builtin types", default=True),
]),
])
Modified: pypy/trunk/pypy/objspace/std/test/test_typeobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_typeobject.py (original)
+++ pypy/trunk/pypy/objspace/std/test/test_typeobject.py Wed Feb 25 14:40:31 2009
@@ -1,5 +1,6 @@
from pypy.objspace.std.objspace import *
from pypy.objspace.std.stdtypedef import *
+from pypy.conftest import gettestobjspace
##class TestSpecialMultimethodCode(testit.TestCase):
@@ -924,3 +925,22 @@
return 0
raises(TypeError, X)
+
+class AppTestMutableBuiltintypes:
+
+ def setup_class(cls):
+ cls.space = gettestobjspace(**{"objspace.std.immutable_builtintypes": False})
+
+ def test_mutate_builtintype(self):
+ list.a = 1
+ def doublelen(self):
+ return len(self) * 2
+ list.doublelen = doublelen
+ l = []
+ assert l.a == 1
+ l.append(100)
+ assert l.doublelen() == 2
+ del list.doublelen
+ del list.a
+ raises(AttributeError, "l.a")
+
Modified: pypy/trunk/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/typeobject.py (original)
+++ pypy/trunk/pypy/objspace/std/typeobject.py Wed Feb 25 14:40:31 2009
@@ -629,7 +629,8 @@
space.set(w_descr, w_type, w_value)
return
- if not w_type.is_heaptype():
+ if (space.config.objspace.std.immutable_builtintypes
+ and not w_type.is_heaptype()):
msg = "can't set attributes on type object '%s'" %(w_type.name,)
raise OperationError(space.w_TypeError, space.wrap(msg))
if name == "__del__" and name not in w_type.dict_w:
@@ -647,8 +648,8 @@
if space.is_data_descr(w_descr):
space.delete(w_descr, w_type)
return
- if not w_type.is_heaptype():
- msg = "can't delete attributes on type object '%s'" %(w_type.name,)
+ if (space.config.objspace.std.immutable_builtintypes
+ and not w_type.is_heaptype()):
raise OperationError(space.w_TypeError, space.wrap(msg))
try:
del w_type.dict_w[name]
More information about the Pypy-commit
mailing list