[pypy-svn] r12330 - in pypy/dist/pypy: interpreter objspace/std
arigo at codespeak.net
arigo at codespeak.net
Sun May 15 23:12:07 CEST 2005
Author: arigo
Date: Sun May 15 23:12:07 2005
New Revision: 12330
Modified:
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/interpreter/function.py
pypy/dist/pypy/interpreter/typedef.py
pypy/dist/pypy/objspace/std/stdtypedef.py
pypy/dist/pypy/objspace/std/typeobject.py
Log:
Moved setdict() to the base W_Root, where it belongs. Changed its signature
to include a 'space' argument. Do the proper check in descr_get_dict().
Added support for 'del a.__dict__' on user-defined instances, which is
essentially equivalent to 'a.__dict__ = {}'... (blame CPython compliancy
tests for the last one)
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Sun May 15 23:12:07 2005
@@ -24,7 +24,13 @@
if not e.match(space, space.w_KeyError):
raise
return None
-
+
+ def setdict(self, space):
+ typename = space.type(self).getname(space, '?')
+ raise OperationError(space.w_TypeError,
+ space.wrap("attribute '__dict__' of %s objects "
+ "is not writable" % typename))
+
def getclass(self, space):
return space.gettypeobject(self.typedef)
Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py (original)
+++ pypy/dist/pypy/interpreter/function.py Sun May 15 23:12:07 2005
@@ -43,8 +43,7 @@
def getdict(self):
return self.w_func_dict
- def setdict(self, w_dict):
- space = self.space
+ def setdict(self, space, w_dict):
if not space.is_true(space.isinstance( w_dict, space.w_dict )):
raise OperationError( space.w_TypeError, space.wrap("setting function's dictionary to a non-dict") )
self.w_func_dict = w_dict
Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py (original)
+++ pypy/dist/pypy/interpreter/typedef.py Sun May 15 23:12:07 2005
@@ -80,8 +80,7 @@
def getdict(self):
return self.w__dict__
- def setdict(self, w_dict):
- space = self.space
+ def setdict(self, space, w_dict):
if not space.is_true(space.isinstance(w_dict, space.w_dict)):
raise OperationError(space.w_TypeError,
space.wrap("setting dictionary to a non-dict"))
@@ -300,7 +299,11 @@
def descr_get_dict(space, obj):
w_dict = obj.getdict()
- assert w_dict is not None, repr(obj)
+ if w_dict is None:
+ typename = space.type(w_obj).getname(space, '?')
+ raise OperationError(space.w_TypeError,
+ space.wrap("descriptor '__dict__' doesn't apply to"
+ " '%s' objects" % typename))
return w_dict
def descr_get_dict_may_be_None(space, obj):
@@ -310,7 +313,7 @@
return w_dict
def descr_set_dict(space, obj, w_dict):
- obj.setdict(w_dict)
+ obj.setdict(space, w_dict)
def generic_ne(space, w_obj1, w_obj2):
if space.eq_w(w_obj1, w_obj2):
Modified: pypy/dist/pypy/objspace/std/stdtypedef.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stdtypedef.py (original)
+++ pypy/dist/pypy/objspace/std/stdtypedef.py Sun May 15 23:12:07 2005
@@ -1,6 +1,7 @@
from pypy.interpreter import eval, function, gateway
from pypy.interpreter.error import OperationError
from pypy.interpreter.typedef import TypeDef, GetSetProperty, Member
+from pypy.interpreter.typedef import descr_get_dict, descr_set_dict
from pypy.interpreter.baseobjspace import SpaceCache
from pypy.objspace.std.model import MultiMethod, FailedToImplement
from pypy.tool.compile import compile2
@@ -31,15 +32,10 @@
a = a.base
return True
-def descr_get_dict(space, w_obj): # xxx typecheck
- w_dict = w_obj.getdict()
- assert w_dict is not None, repr(w_obj)
- return w_dict
+def descr_del_dict(space, w_obj): # blame CPython for the existence of this one
+ w_obj.setdict(space, space.newdict([]))
-def descr_set_dict(space, w_obj, w_dict): # xxx typecheck
- w_obj.setdict(w_dict)
-
-std_dict_descr = GetSetProperty(descr_get_dict, descr_set_dict)
+std_dict_descr = GetSetProperty(descr_get_dict, descr_set_dict, descr_del_dict)
def newmethod(descr_new, unwrap_spec=None):
"NOT_RPYTHON: initialization-time only."
Modified: pypy/dist/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typeobject.py (original)
+++ pypy/dist/pypy/objspace/std/typeobject.py Sun May 15 23:12:07 2005
@@ -253,12 +253,6 @@
dictspec.append((space.wrap(key), w_value))
return space.newdict(dictspec)
- def setdict(w_self, w_dict):
- space = w_self.space
- raise OperationError(space.w_TypeError,
- space.wrap("attribute '__dict__' of type objects "
- "is not writable"))
-
def unwrap(w_self):
if hasattr(w_self.instancetypedef, 'fakedcpytype'):
return w_self.instancetypedef.fakedcpytype
More information about the Pypy-commit
mailing list