[pypy-svn] r18658 - in pypy/dist/pypy/rpython/ootypesystem: . test

mwh at codespeak.net mwh at codespeak.net
Sat Oct 15 19:48:40 CEST 2005


Author: mwh
Date: Sat Oct 15 19:48:38 2005
New Revision: 18658

Modified:
   pypy/dist/pypy/rpython/ootypesystem/ootype.py
   pypy/dist/pypy/rpython/ootypesystem/test/test_ootype.py
Log:
(boria, mwh)
fix bug in ootype._instance.__setattr__ when assigning to a field
present in a superclass.  added test.


Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py	Sat Oct 15 19:48:38 2005
@@ -96,9 +96,16 @@
 
             return self._superclass._has_field(name)
 
-    def _check_field(self, name):
-        if not self._has_field(name):
-	    raise TypeError("No field named %r" % name)
+    def _field_type(self, name):
+        try:
+            return self._fields[name][0]
+        except KeyError:
+	    if self._superclass is None:
+                raise TypeError("No field names %r" % name)
+
+            return self._superclass._field_type(name)
+
+    _check_field = _field_type
 
     def _lookup(self, meth_name):
         meth = self._methods.get(meth_name)
@@ -147,8 +154,8 @@
     def __setattr__(self, name, value):
         self.__getattr__(name)
             
-        if self._TYPE._fields[name][0] != typeOf(value):
-            raise TypeError("Expected type %r" % self._TYPE._fields[name][0])
+        if self._TYPE._field_type(name) != typeOf(value):
+            raise TypeError("Expected type %r" % self._TYPE._field_type(name))
 
         self.__dict__[name] = value
 

Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_ootype.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_ootype.py	Sat Oct 15 19:48:38 2005
@@ -22,6 +22,16 @@
     i.a = 3
     assert i.a == 3
 
+def test_assign_super_attr():
+    C = Instance("test", None, {"a": (Signed, 3)})
+    D = Instance("test2", C, {})
+
+    d = new(D)
+
+    d.a = 1
+
+    assert d.a == 1
+
 def test_runtime_instanciation():
     I = Instance("test", None, {"a": Signed})
     c = runtimeClass(I)



More information about the Pypy-commit mailing list