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

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Jan 10 19:41:18 CET 2007


Author: cfbolz
Date: Wed Jan 10 19:41:16 2007
New Revision: 36429

Modified:
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/objspace/descroperation.py
   pypy/dist/pypy/objspace/std/dictmultiobject.py
   pypy/dist/pypy/objspace/std/dictobject.py
   pypy/dist/pypy/objspace/std/dictstrobject.py
   pypy/dist/pypy/objspace/std/objspace.py
   pypy/dist/pypy/objspace/std/proxyobject.py
Log:
(pedronis, cfbolz): make it possible to track shadowing of type attributes by
instances. only preparation, nothing much working.


Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Wed Jan 10 19:41:16 2007
@@ -27,10 +27,10 @@
             return space.finditem(w_dict, w_attr)
         return None
 
-    def setdictvalue(self, space, w_attr, w_value):
+    def setdictvalue(self, space, w_attr, w_value, shadows_type=True):
         w_dict = self.getdict()
         if w_dict is not None:
-            space.set_str_keyed_item(w_dict, w_attr, w_value)
+            space.set_str_keyed_item(w_dict, w_attr, w_value, shadows_type)
             return True
         return False
     
@@ -434,7 +434,7 @@
         """shortcut for space.int_w(space.hash(w_obj))"""
         return self.int_w(self.hash(w_obj))
 
-    def set_str_keyed_item(self, w_obj, w_key, w_value):
+    def set_str_keyed_item(self, w_obj, w_key, w_value, shadows_type=True):
         return self.setitem(w_obj, w_key, w_value)
     
     def finditem(self, w_obj, w_key):

Modified: pypy/dist/pypy/objspace/descroperation.py
==============================================================================
--- pypy/dist/pypy/objspace/descroperation.py	(original)
+++ pypy/dist/pypy/objspace/descroperation.py	Wed Jan 10 19:41:16 2007
@@ -31,11 +31,13 @@
     def descr__setattr__(space, w_obj, w_name, w_value):
         name = space.str_w(w_name)
         w_descr = space.lookup(w_obj, name)
+        shadows_type = False
         if w_descr is not None:
             if space.is_data_descr(w_descr):
                 space.set(w_descr, w_obj, w_value)
                 return
-        if w_obj.setdictvalue(space, w_name, w_value):
+            shadows_type = True
+        if w_obj.setdictvalue(space, w_name, w_value, shadows_type):
             return
         raiseattrerror(space, w_obj, name, w_descr)
 

Modified: pypy/dist/pypy/objspace/std/dictmultiobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictmultiobject.py	(original)
+++ pypy/dist/pypy/objspace/std/dictmultiobject.py	Wed Jan 10 19:41:16 2007
@@ -41,7 +41,7 @@
     
 ##     def get(self, w_lookup):
 ##         return w_value or None
-##     def setitem_str(self,  w_key, w_value):
+##     def setitem_str(self,  w_key, w_value, shadows_type=True):
 ##         return implementation
 ##     def setitem(self,  w_key, w_value):
 ##         return implementation
@@ -142,7 +142,7 @@
         else:
             return RDictImplementation(self.space).setitem(w_key, w_value)
         #return SmallDictImplementation(self.space, w_key, w_value)
-    def setitem_str(self, w_key, w_value):
+    def setitem_str(self, w_key, w_value, shadows_type=True):
         return StrDictImplementation(self.space).setitem_str(w_key, w_value)
         #return SmallStrDictImplementation(self.space, w_key, w_value)
     def delitem(self, w_key):
@@ -221,7 +221,8 @@
         entry.w_value = w_value
         return self
 
-    setitem_str = setitem
+    def setitem_str(self, w_key, w_value, shadows_type=True):
+        return self.setitem(w_key, w_value)
 
     def delitem(self, w_key):
         entry = self._lookup(w_key)
@@ -321,7 +322,7 @@
             return self._convert_to_rdict().setitem(w_key, w_value)
         return self.setitem_str(w_key, w_value)
     
-    def setitem_str(self, w_key, w_value):
+    def setitem_str(self, w_key, w_value, shadows_type=True):
         entry = self._lookup(self.space.str_w(w_key))
         if entry.w_value is None:
             if self.valid == 4:
@@ -392,7 +393,7 @@
         else:
             return self._as_rdict().setitem(w_key, w_value)
 
-    def setitem_str(self, w_key, w_value):
+    def setitem_str(self, w_key, w_value, shadows_type=True):
         self.content[self.space.str_w(w_key)] = w_value
         return self
 
@@ -451,7 +452,6 @@
             newimpl.setitem(self.space.wrap(k), w_v)
         return newimpl
 
-
 # the following are very close copies of the base classes above
 
 class StrKeyIteratorImplementation(IteratorImplementation):
@@ -496,7 +496,7 @@
         StrDictImplementation.__init__(self, space)
         self.shadowed = [None] * len(BUILTIN_TO_INDEX)
 
-    def setitem_str(self, w_key, w_value):
+    def setitem_str(self, w_key, w_value, shadows_type=True):
         key = self.space.str_w(w_key)
         i = BUILTIN_TO_INDEX.get(key, -1)
         if i != -1:
@@ -533,7 +533,10 @@
     def setitem(self, w_key, w_value):
         self.content[w_key] = w_value
         return self
-    setitem_str = setitem
+
+    def setitem_str(self, w_key, w_value, shadows_type=True):
+        return self.setitem(w_key, w_value)
+
     def delitem(self, w_key):
         del self.content[w_key]
         if self.content:
@@ -665,7 +668,7 @@
         else:
             return self._as_rdict().setitem(w_key, w_value)
 
-    def setitem_str(self, w_key, w_value):
+    def setitem_str(self, w_key, w_value, shadows_type=True):
         m = ~len(self.structure.other_structs)
         key = self.space.str_w(w_key)
         i = self.structure.keys.get(key, m)
@@ -874,7 +877,7 @@
         self.content[w_key] = w_value
         self.info.maxcontents = max(self.info.maxcontents, len(self.content))
         return self
-    def setitem_str(self, w_key, w_value):
+    def setitem_str(self, w_key, w_value, shadows_type=True):
         self.info.setitem_strs += 1
         return self.setitem(w_key, w_value)
     def delitem(self, w_key):
@@ -990,8 +993,9 @@
         else:
             return w_default
 
-    def set_str_keyed_item(w_dict, w_key, w_value):
-        w_dict.implementation = w_dict.implementation.setitem_str(w_key, w_value)
+    def set_str_keyed_item(w_dict, w_key, w_value, shadows_type=True):
+        w_dict.implementation = w_dict.implementation.setitem_str(
+            w_key, w_value, shadows_type)
 
 registerimplementation(W_DictMultiObject)
 

Modified: pypy/dist/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictobject.py	(original)
+++ pypy/dist/pypy/objspace/std/dictobject.py	Wed Jan 10 19:41:16 2007
@@ -41,7 +41,7 @@
     def get(w_dict, w_lookup, w_default):
         return w_dict.content.get(w_lookup, w_default)
 
-    def set_str_keyed_item(w_dict, w_key, w_value):
+    def set_str_keyed_item(w_dict, w_key, w_value, shadows_type=True):
         w_dict.content[w_key] = w_value
 
 registerimplementation(W_DictObject)

Modified: pypy/dist/pypy/objspace/std/dictstrobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictstrobject.py	(original)
+++ pypy/dist/pypy/objspace/std/dictstrobject.py	Wed Jan 10 19:41:16 2007
@@ -53,7 +53,8 @@
                 w_self.str2object()
                 w_self.content[w_k] = w_v
 
-    set_str_keyed_item = setitem
+    def set_str_keyed_item(w_self, w_k, w_v, shadows_type=True):
+        return w_self.setitem(w_k, w_v)
 
     def str2object(w_self):
         """ Moves all items in the content_str dict to content. """

Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py	(original)
+++ pypy/dist/pypy/objspace/std/objspace.py	Wed Jan 10 19:41:16 2007
@@ -511,10 +511,10 @@
             return w_obj.get(w_key, None)
         return ObjSpace.finditem(self, w_obj, w_key)
 
-    def set_str_keyed_item(self, w_obj, w_key, w_value):
+    def set_str_keyed_item(self, w_obj, w_key, w_value, shadows_type=True):
         # performance shortcut to avoid creating the OperationError(KeyError)
         if type(w_obj) is self.DictObjectCls:
-            w_obj.set_str_keyed_item(w_key, w_value)
+            w_obj.set_str_keyed_item(w_key, w_value, shadows_type)
         else:
             self.setitem(w_obj, w_key, w_value)
 

Modified: pypy/dist/pypy/objspace/std/proxyobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/proxyobject.py	(original)
+++ pypy/dist/pypy/objspace/std/proxyobject.py	Wed Jan 10 19:41:16 2007
@@ -42,7 +42,7 @@
                     raise
                 return None
         
-        def setdictvalue(self, space, w_attr, w_value):
+        def setdictvalue(self, space, w_attr, w_value, shadows_type=True):
             try:
                 space.call_function(self.w_controller, space.wrap('__setattr__'),
                    w_attr, w_value)



More information about the Pypy-commit mailing list