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

antocuni at codespeak.net antocuni at codespeak.net
Thu Jul 6 16:28:27 CEST 2006


Author: antocuni
Date: Thu Jul  6 16:28:24 2006
New Revision: 29681

Modified:
   pypy/dist/pypy/rpython/ootypesystem/rclass.py
   pypy/dist/pypy/rpython/test/test_rclass.py
Log:
(antocuni, arigo)

Add an abstract accessor method for class attributes who are not
defined in the base class instead of failing.

Don't skip the test_common_class_attribute, which no longer fails.



Modified: pypy/dist/pypy/rpython/ootypesystem/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rclass.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/rclass.py	Thu Jul  6 16:28:24 2006
@@ -291,9 +291,6 @@
                         # classes to see if it's defined in a parent but only
                         # actually first used in self.classdef.
                         value = selfdesc.read_attribute(name, None)
-                        if value is None:
-                            raise TyperError("class %r has no attribute %r" % (
-                                self.classdef.name, name))
 
                     # a non-method class attribute
                     if not attrdef.s_value.is_constant():
@@ -319,19 +316,23 @@
         # really overridden in subclasses
         for mangled, (s_value, value) in classattributes.items():
             r = self.rtyper.getrepr(s_value)
-            oovalue = r.convert_desc_or_const(value)
-            m = self.attach_class_attr_accessor(mangled, oovalue,
-                                                r.lowleveltype)
+            m = self.attach_class_attr_accessor(mangled, value, r)
 
-    def attach_class_attr_accessor(self, mangled, oovalue, oovaluetype):
+    def attach_class_attr_accessor(self, mangled, value, r_value):
         def ll_getclassattr(self):
             return oovalue
-        ll_getclassattr = func_with_new_name(ll_getclassattr,
-                                             'll_get_' + mangled)
-        graph = self.rtyper.annotate_helper(ll_getclassattr, [self.lowleveltype])
-        M = ootype.Meth([], oovaluetype)
-        m = ootype.meth(M, _name=mangled, _callable=ll_getclassattr,
-                        graph=graph)
+
+        M = ootype.Meth([], r_value.lowleveltype)
+        if value is None:
+            m = ootype.meth(M, _name=mangled, abstract=True)
+        else:
+            oovalue = r_value.convert_desc_or_const(value)
+            ll_getclassattr = func_with_new_name(ll_getclassattr,
+                                                 'll_get_' + mangled)
+            graph = self.rtyper.annotate_helper(ll_getclassattr, [self.lowleveltype])
+            m = ootype.meth(M, _name=mangled, _callable=ll_getclassattr,
+                            graph=graph)
+
         ootype.addMethods(self.lowleveltype, {mangled: m})
 
     def get_ll_hash_function(self):

Modified: pypy/dist/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rclass.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rclass.py	Thu Jul  6 16:28:24 2006
@@ -496,7 +496,6 @@
 
 
     def test_common_class_attribute(self):
-        self._skip_oo('common class attribute')
         class A:
             def meth(self):
                 return self.x



More information about the Pypy-commit mailing list