[pypy-svn] r28786 - in pypy/dist/pypy: annotation rpython tool

arigo at codespeak.net arigo at codespeak.net
Wed Jun 14 19:22:15 CEST 2006


Author: arigo
Date: Wed Jun 14 19:22:14 2006
New Revision: 28786

Modified:
   pypy/dist/pypy/annotation/builtin.py
   pypy/dist/pypy/annotation/description.py
   pypy/dist/pypy/rpython/rbuiltin.py
   pypy/dist/pypy/tool/ansi_print.py
Log:
Some 2.5 compatibility hacks.


Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py	(original)
+++ pypy/dist/pypy/annotation/builtin.py	Wed Jun 14 19:22:14 2006
@@ -339,7 +339,7 @@
     return SomeObject()
 
 # collect all functions
-import __builtin__
+import __builtin__, exceptions
 BUILTIN_ANALYZERS = {}
 EXTERNAL_TYPE_ANALYZERS = {}
 for name, value in globals().items():
@@ -365,11 +365,22 @@
 BUILTIN_ANALYZERS[pypy.rpython.rstack.yield_current_frame_to_caller] = (
     rstack_yield_current_frame_to_caller)
 
-BUILTIN_ANALYZERS[Exception.__init__.im_func] = exception_init
-BUILTIN_ANALYZERS[OSError.__init__.im_func] = exception_init
-# this one is needed otherwise when annotating assert in a test we may try to annotate 
-# py.test AssertionError.__init__ .
-BUILTIN_ANALYZERS[AssertionError.__init__.im_func] = exception_init
+def setup_Exception_init(mod):
+    # Set a BUILTIN_ANALYZERS for the __init__ of each exception class.
+    # This is required for 2.5; previously, we could set just a few __init__:
+    # Exception, OSError, and AssertionError (for running on top of py.test)
+    for name in dir(exceptions):
+        obj = getattr(mod, name, None)
+        if isinstance(obj, type(Exception)) and issubclass(obj, Exception):
+            try:
+                f = obj.__init__.im_func
+            except AttributeError:
+                f = obj.__init__
+            BUILTIN_ANALYZERS[f] = exception_init
+setup_Exception_init(__builtin__)
+setup_Exception_init(exceptions)
+del setup_Exception_init
+
 BUILTIN_ANALYZERS[sys.getdefaultencoding] = conf
 import unicodedata
 BUILTIN_ANALYZERS[unicodedata.decimal] = unicodedata_decimal # xxx

Modified: pypy/dist/pypy/annotation/description.py
==============================================================================
--- pypy/dist/pypy/annotation/description.py	(original)
+++ pypy/dist/pypy/annotation/description.py	Wed Jun 14 19:22:14 2006
@@ -366,6 +366,10 @@
             baselist = list(cls.__bases__)
             baselist.reverse()
 
+            # special case: skip BaseException in Python 2.5
+            if cls is Exception:
+                baselist = []
+
             for b1 in baselist:
                 if b1 is object:
                     continue

Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/rbuiltin.py	Wed Jun 14 19:22:14 2006
@@ -301,15 +301,30 @@
 
 
 # collect all functions
-import __builtin__
+import __builtin__, exceptions
 BUILTIN_TYPER = {}
 for name, value in globals().items():
     if name.startswith('rtype_builtin_'):
         original = getattr(__builtin__, name[14:])
         BUILTIN_TYPER[original] = value
-BUILTIN_TYPER[Exception.__init__.im_func] = rtype_Exception__init__
-BUILTIN_TYPER[AssertionError.__init__.im_func] = rtype_Exception__init__
-BUILTIN_TYPER[OSError.__init__.im_func] = rtype_OSError__init__
+
+def setup_Exception_init(mod):
+    # should be kept in sync with annotation/builtin.py.
+    for name in dir(exceptions):
+        obj = getattr(mod, name, None)
+        if isinstance(obj, type(Exception)) and issubclass(obj, Exception):
+            try:
+                f = obj.__init__.im_func
+            except AttributeError:
+                f = obj.__init__
+            if issubclass(obj, OSError):
+                BUILTIN_TYPER[f] = rtype_OSError__init__
+            else:
+                BUILTIN_TYPER[f] = rtype_Exception__init__
+setup_Exception_init(__builtin__)
+setup_Exception_init(exceptions)
+del setup_Exception_init
+
 BUILTIN_TYPER[object.__init__] = rtype_object__init__
 # annotation of low-level types
 

Modified: pypy/dist/pypy/tool/ansi_print.py
==============================================================================
--- pypy/dist/pypy/tool/ansi_print.py	(original)
+++ pypy/dist/pypy/tool/ansi_print.py	Wed Jun 14 19:22:14 2006
@@ -79,5 +79,8 @@
             return '\n'.join(lines)
     ExcSubclass.__name__ = cls.__name__ + "'"
     ExcSubclass.__module__ = cls.__module__
-    e.__class__ = ExcSubclass
+    try:
+        e.__class__ = ExcSubclass
+    except TypeError:   # doesn't work any more on 2.5 :-(
+        pass
     raise ExcSubclass, e, tb



More information about the Pypy-commit mailing list