[pypy-svn] r6388 - in pypy/trunk/src/pypy/translator: . test

arigo at codespeak.net arigo at codespeak.net
Sat Sep 11 00:53:16 CEST 2004


Author: arigo
Date: Sat Sep 11 00:53:16 2004
New Revision: 6388

Modified:
   pypy/trunk/src/pypy/translator/classtyper.py
   pypy/trunk/src/pypy/translator/test/snippet.py
Log:
Abstract base classes can have uninitialized class attributes (e.g. missing
virtual methods).


Modified: pypy/trunk/src/pypy/translator/classtyper.py
==============================================================================
--- pypy/trunk/src/pypy/translator/classtyper.py	(original)
+++ pypy/trunk/src/pypy/translator/classtyper.py	Sat Sep 11 00:53:16 2004
@@ -148,9 +148,12 @@
         v1 = Constant(cls)
         # initialize class attributes
         for fld in self.class_fields:
-            value = getattr(cls, fld.name)
-            op('initclassattr', v1, Constant(fld.name), Constant(value),
-               s_result = annmodel.SomeImpossibleValue())
+            # some attributes might be missing from 'cls' if it is an abstract
+            # base class.  We left the field uninitialized in this case.
+            if hasattr(cls, fld.name):
+                value = getattr(cls, fld.name)
+                op('initclassattr', v1, Constant(fld.name), Constant(value),
+                   s_result = annmodel.SomeImpossibleValue())
         # finally, return None
         graph = FunctionGraph('%s_typenew' % self.name, b)
         self.bindings[graph.getreturnvar()] = annmodel.immutablevalue(None)

Modified: pypy/trunk/src/pypy/translator/test/snippet.py
==============================================================================
--- pypy/trunk/src/pypy/translator/test/snippet.py	(original)
+++ pypy/trunk/src/pypy/translator/test/snippet.py	Sat Sep 11 00:53:16 2004
@@ -319,7 +319,9 @@
 def prime(n=int):
     return len([i for i in range(1,n+1) if n%i==0]) == 2
 
-class A1:
+class A0:
+    pass
+class A1(A0):
     clsattr = 123
 class A2(A1):
     clsattr = 456
@@ -327,7 +329,7 @@
     clsattr = 789
 class A4(A3):
     pass
-class A5(A1):
+class A5(A0):
     clsattr = 101112
 
 def classattribute(flag=int):



More information about the Pypy-commit mailing list