[pypy-svn] r9727 - in pypy/dist/pypy: annotation interpreter

pedronis at codespeak.net pedronis at codespeak.net
Thu Mar 10 16:00:10 CET 2005


Author: pedronis
Date: Thu Mar 10 16:00:10 2005
New Revision: 9727

Modified:
   pypy/dist/pypy/annotation/binaryop.py
   pypy/dist/pypy/interpreter/pycode.py
Log:
added sanity check and workaround to problems when to subclasses of a class contain an identical function
but is not correct to consider this to belong to a superclass because unrelated subclasses could obviously
don't have it.

we either need to manually avoid this problem or make the pbc representation more complicated.




Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py	(original)
+++ pypy/dist/pypy/annotation/binaryop.py	Thu Mar 10 16:00:10 2005
@@ -283,7 +283,7 @@
             return SomeBuiltin(bltn1.analyser, s_self)
 
 class __extend__(pairtype(SomePBC, SomePBC)):
-    def union((pbc1, pbc2)):
+    def union((pbc1, pbc2)):       
         if len(pbc2.prebuiltinstances) > len(pbc1.prebuiltinstances):
             pbc1, pbc2 = pbc2, pbc1
         d = pbc1.prebuiltinstances.copy()
@@ -294,7 +294,15 @@
                         "union failed for %r with classdefs %r and %r" % 
                         (x, classdef, d[x]))
                 if isclassdef(classdef):
+                    classdef2 = classdef
                     classdef = classdef.commonbase(d[x])
+                    for cand in classdef.getmro():
+                        if x in cand.__dict__.values():
+                            break
+                    else:
+                        assert False, ("confused pbc union trying unwarranted"
+                                       "moving up of method %s from pair %s %s" %
+                                       (x, d[x], classdef2))
             d[x] = classdef
         result =  SomePBC(d)
         return result

Modified: pypy/dist/pypy/interpreter/pycode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycode.py	(original)
+++ pypy/dist/pypy/interpreter/pycode.py	Thu Mar 10 16:00:10 2005
@@ -56,14 +56,25 @@
     from pypy.interpreter.nestedscope import PyNestedScopeFrame
     from pypy.interpreter.generator import GeneratorFrame
 
+    def fresh_GeneratorFrame_methods():
+        import types
+        from pypy.tool.hack import func_with_new_name
+        dic = GeneratorFrame.__dict__.copy()
+        for n in dic:
+            x = dic[n]
+            if isinstance(x, types.FunctionType):
+                dic[n] = func_with_new_name(x, x.__name__)
+        print dic
+        return dic
+
     frame_classes[0]                = PyInterpFrame
     frame_classes[NESTED]           = PyNestedScopeFrame
     frame_classes[GENERATOR]        = type('PyGeneratorFrame',
                                            (PyInterpFrame,),
-                                           GeneratorFrame.__dict__.copy())
+                                           fresh_GeneratorFrame_methods())
     frame_classes[NESTED|GENERATOR] = type('PyNestedScopeGeneratorFrame',
                                            (PyNestedScopeFrame,),
-                                           GeneratorFrame.__dict__.copy())
+                                           fresh_GeneratorFrame_methods())
 
 class PyCode(eval.Code):
     "CPython-style code objects."



More information about the Pypy-commit mailing list