[pypy-svn] r14173 - pypy/dist/pypy/rpython

arigo at codespeak.net arigo at codespeak.net
Sun Jul 3 19:44:51 CEST 2005


Author: arigo
Date: Sun Jul  3 19:44:49 2005
New Revision: 14173

Modified:
   pypy/dist/pypy/rpython/rpbc.py
Log:
Sanitized the selection of PBC representations.


Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/rpbc.py	Sun Jul  3 19:44:49 2005
@@ -16,6 +16,7 @@
         # categories below, and doesn't for example mix functions, classes
         # and methods.
         call_families = rtyper.annotator.getpbccallfamilies()
+        userclasses = rtyper.annotator.getuserclasses()
         choices = {}
         for x, classdef in self.prebuiltinstances.items():
             cdefflag = isclassdef(classdef)
@@ -26,31 +27,40 @@
             if isinstance(x, types.MethodType) and x.im_self is None:
                 x = x.im_func
 
-            # callable or frozen object?
-            if (classdef, x) in call_families:
-                # what type of callable?
-                if isinstance(x, types.FunctionType):
-                    if cdefflag:
-                        choice = MethodsPBCRepr
-                        cdefflag = False
-                    else:
-                        choice = FunctionsPBCRepr
-                elif isinstance(x, (type, types.ClassType)):
+            if cdefflag:
+                # methods of a run-time instance
+                if not isinstance(x, types.FunctionType):
+                    raise TyperError("%r appears to be a method bound to %r, "
+                                     "but it is not a function" % (
+                        x, classdef))
+                choice = MethodsPBCRepr
+
+            elif isinstance(x, (type, types.ClassType)):
+                # classes
+                if x in userclasses:
+                    # user classes
                     choice = ClassesPBCRepr
+                elif type(x) is type and x.__module__ == '__builtin__':
+                    # special case for built-in types, seen in faking
+                    choice = getPyObjRepr
+                else:
+                    raise TyperError("don't known about class %r" % (x,))
+
+            elif (classdef, x) in call_families:
+                # other kind of callable
+                if isinstance(x, types.FunctionType):
+                    # function
+                    choice = FunctionsPBCRepr
                 elif isinstance(x, types.MethodType):
+                    # prebuilt bound method
                     choice = MethodOfFrozenPBCRepr
                 else:
                     raise TyperError("don't know about callable %r" % (x,))
-            elif type(x) is type and x.__module__ == '__builtin__':
-                # special case for built-in types, seen in faking
-                choice = getPyObjRepr
+
             else:
-                # frozen object
+                # otherwise, just assume it's a plain frozen object
                 choice = getFrozenPBCRepr
 
-            if cdefflag:
-                raise TyperError("unexpected classdef in PBC set %r" % (
-                    self.prebuiltinstances,))
             choices[choice] = True
 
         if len(choices) > 1:



More information about the Pypy-commit mailing list