[pypy-svn] r12332 - in pypy/dist/pypy: interpreter objspace objspace/std

arigo at codespeak.net arigo at codespeak.net
Sun May 15 23:46:20 CEST 2005


Author: arigo
Date: Sun May 15 23:46:20 2005
New Revision: 12332

Modified:
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/interpreter/module.py
   pypy/dist/pypy/interpreter/typedef.py
   pypy/dist/pypy/objspace/descroperation.py
   pypy/dist/pypy/objspace/std/typeobject.py
Log:
Sanitized the __dict__ attribute of module objects, by giving up trying to
emulate CPython's behavior of having __dict__ set to None if module.__init__
is not called, but changed to a real dict as soon as an attribute is stored
into the module...

Got rid of space.getdict() and space.getdictvalue() -- veeery old interface
mostly used in descroperation.py only, now replaced by W_Root.getdict/value().



Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Sun May 15 23:46:20 2005
@@ -25,7 +25,7 @@
                     raise
         return None
 
-    def setdict(self, space):
+    def setdict(self, space, w_dict):
         typename = space.type(self).getname(space, '?')
         raise OperationError(space.w_TypeError,
                              space.wrap("attribute '__dict__' of %s objects "

Modified: pypy/dist/pypy/interpreter/module.py
==============================================================================
--- pypy/dist/pypy/interpreter/module.py	(original)
+++ pypy/dist/pypy/interpreter/module.py	Sun May 15 23:46:20 2005
@@ -12,11 +12,9 @@
         self.space = space
         if w_dict is None: 
             w_dict = space.newdict([])
-        elif space.is_w(w_dict, space.w_None):
-            w_dict = None
         self.w_dict = w_dict 
         self.w_name = w_name 
-        if w_name is not None and w_dict is not None:
+        if w_name is not None:
             space.setitem(w_dict, space.wrap('__name__'), w_name) 
 
     def getdict(self):
@@ -24,7 +22,7 @@
 
     def descr_module__new__(space, w_subtype, __args__):
         module = space.allocate_instance(Module, w_subtype)
-        Module.__init__(module, space, space.wrap('?'), space.w_None)
+        Module.__init__(module, space, None)
         return space.wrap(module)
 
     def descr_module__init__(self, w_name, w_doc=None):
@@ -32,8 +30,5 @@
         self.w_name = w_name
         if w_doc is None:  
             w_doc = space.w_None
-        w_dict = self.getdict()
-        if w_dict is None:
-            w_dict = self.w_dict = space.newdict([])
-        space.setitem(w_dict, space.wrap('__name__'), w_name)
-        space.setitem(w_dict, space.wrap('__doc__'), w_doc)
+        space.setitem(self.w_dict, space.wrap('__name__'), w_name)
+        space.setitem(self.w_dict, space.wrap('__doc__'), w_doc)

Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py	(original)
+++ pypy/dist/pypy/interpreter/typedef.py	Sun May 15 23:46:20 2005
@@ -306,12 +306,6 @@
                                         " '%s' objects" % typename))
     return w_dict
 
-def descr_get_dict_may_be_None(space, obj):
-    w_dict = obj.getdict()
-    if w_dict is None:
-        return space.w_None
-    return w_dict
-
 def descr_set_dict(space, obj, w_dict):
     obj.setdict(space, w_dict)
 
@@ -391,7 +385,7 @@
     __new__ = interp2app(Module.descr_module__new__.im_func,
                          unwrap_spec=[ObjSpace, W_Root, Arguments]),
     __init__ = interp2app(Module.descr_module__init__),
-    __dict__ = GetSetProperty(descr_get_dict_may_be_None, cls=Module), # module dictionaries are readonly attributes
+    __dict__ = GetSetProperty(descr_get_dict, cls=Module), # module dictionaries are readonly attributes
     __doc__ = 'module(name[, doc])\n\nCreate a module object.\nThe name must be a string; the optional doc argument can have any type.'
     )
 

Modified: pypy/dist/pypy/objspace/descroperation.py
==============================================================================
--- pypy/dist/pypy/objspace/descroperation.py	(original)
+++ pypy/dist/pypy/objspace/descroperation.py	Sun May 15 23:46:20 2005
@@ -21,7 +21,7 @@
         if w_descr is not None:
             if space.is_data_descr(w_descr):
                 return space.get(w_descr, w_obj)
-        w_value = space.getdictvalue(w_obj, name)
+        w_value = w_obj.getdictvalue(space, name)
         if w_value is not None:
             return w_value
         if w_descr is not None:
@@ -33,10 +33,12 @@
         w_descr = space.lookup(w_obj, name)
         if w_descr is not None:
             if space.is_data_descr(w_descr):
-                return space.set(w_descr, w_obj, w_value)
-        w_dict = space.getdict(w_obj)
+                space.set(w_descr, w_obj, w_value)
+                return
+        w_dict = w_obj.getdict()
         if w_dict is not None:
-            return space.setitem(w_dict, w_name, w_value)
+            space.setitem(w_dict, w_name, w_value)
+            return
         raiseattrerror(space, w_obj, name, w_descr)
 
     def descr__delattr__(space, w_obj, w_name):
@@ -45,17 +47,18 @@
         if w_descr is not None:
             if space.is_data_descr(w_descr):
                 return space.delete(w_descr, w_obj)
-        w_dict = space.getdict(w_obj)
+        w_dict = w_obj.getdict()
         if w_dict is not None:
             try:
-                return space.delitem(w_dict, w_name)
+                space.delitem(w_dict, w_name)
+                return
             except OperationError, ex:
                 if not ex.match(space, space.w_KeyError):
                     raise
         raiseattrerror(space, w_obj, name, w_descr)
 
     def descr__init__(space, w_obj, __args__):
-        pass   # XXX some strange checking maybe
+        pass
 
 class DescrOperation:
     _mixin_ = True
@@ -64,12 +67,6 @@
         ec._compare_nesting = 0
         ec._cmp_state = {}
 
-    def getdict(space, w_obj):
-        return w_obj.getdict()
-
-    def getdictvalue(space, w_obj, attr):
-        return w_obj.getdictvalue(space, attr)
-
     def is_data_descr(space, w_obj):
         return space.lookup(w_obj, '__set__') is not None
 

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:46:20 2005
@@ -204,7 +204,7 @@
         # note that this doesn't call __get__ on the result at all
         space = w_self.space
         for w_class in w_self.mro_w:
-            w_value = space.getdictvalue(w_class, key)
+            w_value = w_class.getdictvalue(space, key)
             if w_value is not None:
                 return w_value
         return None
@@ -214,7 +214,7 @@
         # attribute was found
         space = w_self.space
         for w_class in w_self.mro_w:
-            w_value = space.getdictvalue(w_class, key)
+            w_value = w_class.getdictvalue(space, key)
             if w_value is not None:
                 return w_class, w_value
         return None, None



More information about the Pypy-commit mailing list