[pypy-svn] r21615 - pypy/dist/pypy/annotation

pedronis at codespeak.net pedronis at codespeak.net
Sat Dec 31 18:44:31 CET 2005


Author: pedronis
Date: Sat Dec 31 18:44:29 2005
New Revision: 21615

Modified:
   pypy/dist/pypy/annotation/bookkeeper.py
   pypy/dist/pypy/annotation/builtin.py
   pypy/dist/pypy/annotation/description.py
Log:
avoid to build classdefs for builtin types (was happening because of the somepbc-refactoring changes)



Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py	(original)
+++ pypy/dist/pypy/annotation/bookkeeper.py	Sat Dec 31 18:44:29 2005
@@ -409,7 +409,10 @@
             elif isinstance(pyobj, (type, types.ClassType)):
                 if pyobj is object:
                     raise Exception, "ClassDesc for object not supported"
-                result = description.ClassDesc(self, pyobj)
+                if pyobj.__module__ == '__builtin__': # avoid making classdefs for builtin types
+                    result = self.getfrozen(pyobj)
+                else:
+                    result = description.ClassDesc(self, pyobj)
             elif isinstance(pyobj, types.MethodType):
                 if pyobj.im_self is None:   # unbound
                     return self.getdesc(pyobj.im_func)
@@ -434,17 +437,17 @@
             else:
                 # must be a frozen pre-built constant, but let's check
                 assert pyobj._freeze_()
-                result = description.FrozenDesc(self, pyobj)
-                cls = result.knowntype
-                if cls not in self.pbctypes:
-                    self.pbctypes[cls] = True
-                    # XXX what to do about this old check?:
-                    #if cls in self.userclasses:
-                    #    self.warning("making some PBC of type %r, which has "
-                    #                 "already got a ClassDef" % (cls,))
+                result = self.getfrozen(pyobj)
             self.descs[pyobj] = result
             return result
 
+    def getfrozen(self, pyobj):
+        result = description.FrozenDesc(self, pyobj)
+        cls = result.knowntype
+        if cls not in self.pbctypes:
+            self.pbctypes[cls] = True
+        return result
+
     def getmethoddesc(self, funcdesc, originclassdef, selfclassdef, name):
         key = funcdesc, originclassdef, selfclassdef, name
         try:

Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py	(original)
+++ pypy/dist/pypy/annotation/builtin.py	Sat Dec 31 18:44:29 2005
@@ -110,7 +110,33 @@
 
 def our_issubclass(cls1, cls2):
     """ we're going to try to be less silly in the face of old-style classes"""
-    return cls2 is object or issubclass(cls1, cls2)
+    from pypy.annotation.classdef import ClassDef
+    if cls2 is object:
+        return True
+    def classify(cls):
+        if isinstance(cls, ClassDef):
+            return 'def'
+        if cls.__module__ == '__builtin__':
+            return 'builtin'
+        else:
+            return 'cls'
+    kind1 = classify(cls1)
+    kind2 = classify(cls2)
+    if kind1 != 'def' and kind2 != 'def':
+        return issubclass(cls1, cls2)
+    if kind1 == 'builtin' and kind2 == 'def':
+        return False
+    elif kind1 == 'def' and kind2 == 'builtin':
+        return issubclass(object, cls2)
+    else:
+        bk = getbookkeeper()
+        def toclassdef(kind, cls):
+            if kind != 'def':
+                return bk.getuniqueclassdef(cls)
+            else:
+                return cls
+        return toclassdef(kind1, cls1).issubclass(toclassdef(kind2, cls2))
+
 
 def builtin_isinstance(s_obj, s_type, variables=None):
     r = SomeBool() 
@@ -138,13 +164,6 @@
  
             if s_obj.is_constant():
                 r.const = isinstance(s_obj.const, typ)
-            elif isinstance(s_obj, SomeInstance):
-                typdef = getbookkeeper().getuniqueclassdef(typ)
-                if s_obj.classdef.issubclass(typdef):
-                    if not s_obj.can_be_none():
-                        r.const = True 
-                elif not typdef.issubclass(s_obj.classdef):
-                    r.const = False
             elif our_issubclass(s_obj.knowntype, typ):
                 if not s_obj.can_be_none():
                     r.const = True 

Modified: pypy/dist/pypy/annotation/description.py
==============================================================================
--- pypy/dist/pypy/annotation/description.py	(original)
+++ pypy/dist/pypy/annotation/description.py	Sat Dec 31 18:44:29 2005
@@ -320,6 +320,7 @@
         self._classdefs = {}
 
         if pyobj is not None:
+            assert pyobj.__module__ != '__builtin__'
             cls = pyobj
             base = object
             baselist = list(cls.__bases__)



More information about the Pypy-commit mailing list