[pypy-svn] r76849 - in pypy/branch/better-map-instances/pypy: module/__builtin__ module/__builtin__/test objspace/std
cfbolz at codespeak.net
cfbolz at codespeak.net
Fri Sep 3 11:54:09 CEST 2010
Author: cfbolz
Date: Fri Sep 3 11:54:07 2010
New Revision: 76849
Modified:
pypy/branch/better-map-instances/pypy/module/__builtin__/interp_classobj.py
pypy/branch/better-map-instances/pypy/module/__builtin__/test/test_classobj.py
pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py
Log:
(cfbolz, arigo looking): make mapdict work with old-style classes
Modified: pypy/branch/better-map-instances/pypy/module/__builtin__/interp_classobj.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/module/__builtin__/interp_classobj.py (original)
+++ pypy/branch/better-map-instances/pypy/module/__builtin__/interp_classobj.py Fri Sep 3 11:54:07 2010
@@ -5,6 +5,8 @@
from pypy.interpreter.typedef import TypeDef
from pypy.interpreter.argument import Arguments
from pypy.interpreter.baseobjspace import Wrappable
+from pypy.interpreter.typedef import GetSetProperty, descr_get_dict
+from pypy.interpreter.typedef import descr_set_dict
from pypy.rlib.rarithmetic import r_uint, intmask
from pypy.rlib.objectmodel import compute_identity_hash
from pypy.rlib.debug import make_sure_not_resized
@@ -402,7 +404,7 @@
if name and name[0] == "_":
if name == '__dict__':
# use setdict to raise the error
- self.setdict(space, None)
+ self.setdict(space, space.w_None)
return
elif name == '__class__':
# use set_oldstyle_class to raise the error
@@ -706,6 +708,14 @@
rmeth,
unwrap_spec=["self", ObjSpace, W_Root])
+
+def descr_del_dict(space, w_inst):
+ # use setdict to raise the error
+ self.setdict(space, space.w_None)
+
+dict_descr = GetSetProperty(descr_get_dict, descr_set_dict, descr_del_dict)
+dict_descr.name = '__dict__'
+
W_InstanceObject.typedef = TypeDef("instance",
__new__ = interp2app(descr_instance_new),
__getattribute__ = interp2app(W_InstanceObject.descr_getattribute,
@@ -757,6 +767,7 @@
unwrap_spec=['self', ObjSpace]),
__del__ = interp2app(W_InstanceObject.descr_del,
unwrap_spec=['self', ObjSpace]),
+ __dict__ = dict_descr,
**rawdict
)
W_InstanceObject.typedef.acceptable_as_base_class = False
Modified: pypy/branch/better-map-instances/pypy/module/__builtin__/test/test_classobj.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/module/__builtin__/test/test_classobj.py (original)
+++ pypy/branch/better-map-instances/pypy/module/__builtin__/test/test_classobj.py Fri Sep 3 11:54:07 2010
@@ -815,3 +815,22 @@
a = 1
b = 2
assert self.is_strdict(A)
+
+class AppTestOldStyleMapDict(AppTestOldstyle):
+ def setup_class(cls):
+ cls.space = gettestobjspace(**{"objspace.std.withmapdict": True})
+ if option.runappdirect:
+ py.test.skip("can only be run on py.py")
+ def has_mapdict(space, w_inst):
+ return space.wrap(w_inst._get_mapdict_map() is not None)
+ cls.w_has_mapdict = cls.space.wrap(gateway.interp2app(has_mapdict))
+
+
+ def test_has_mapdict(self):
+ class A:
+ def __init__(self):
+ self.x = 42
+ a = A()
+ assert a.x == 42
+ assert self.has_mapdict(a)
+
Modified: pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py (original)
+++ pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py Fri Sep 3 11:54:07 2010
@@ -324,8 +324,10 @@
self._become(new_obj)
def user_setup(self, space, w_subtype):
+ from pypy.module.__builtin__.interp_classobj import W_InstanceObject
self.space = space
- assert not self.typedef.hasdict
+ assert (not self.typedef.hasdict or
+ self.typedef is W_InstanceObject.typedef)
self._init_empty(w_subtype.terminator)
def getslotvalue(self, index):
More information about the Pypy-commit
mailing list