[pypy-svn] r78214 - in pypy/trunk/pypy: objspace/flow translator/c/test

afa at codespeak.net afa at codespeak.net
Fri Oct 22 16:31:52 CEST 2010


Author: afa
Date: Fri Oct 22 16:31:50 2010
New Revision: 78214

Modified:
   pypy/trunk/pypy/objspace/flow/flowcontext.py
   pypy/trunk/pypy/translator/c/test/test_typed.py
Log:
Replace the exc_typ argument of the __exit__ method with an object
that is likely to break annotation if used in any way 
(except maybe with the 'is' operator)


Modified: pypy/trunk/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/trunk/pypy/objspace/flow/flowcontext.py	(original)
+++ pypy/trunk/pypy/objspace/flow/flowcontext.py	Fri Oct 22 16:31:50 2010
@@ -504,8 +504,10 @@
                                                       *args, **kwds)
 
     def call_contextmanager_exit_function(self, w_func, w_typ, w_val, w_tb):
-        # The annotator won't allow to merge exception types with None.
-        # XXX return an object which will break translation when it is used
-        w_typ = self.space.w_None
+        if w_typ is not self.space.w_None:
+            # The annotator won't allow to merge exception types with None.
+            # Replace it with an object which will break translation when used
+            # (except maybe with 'exc_typ is None')
+            w_typ = self.space.wrap(self.space)
         return self.space.call_function(w_func, w_typ, w_val, w_tb)
 

Modified: pypy/trunk/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/trunk/pypy/translator/c/test/test_typed.py	(original)
+++ pypy/trunk/pypy/translator/c/test/test_typed.py	Fri Oct 22 16:31:50 2010
@@ -833,21 +833,32 @@
             def __enter__(self):
                 state.append('acquire')
                 return self
-            def __exit__(self, *args):
-                if args[1] is not None:
+            def __exit__(self, typ, value, tb):
+                if typ is not None:
+                    if value is None:
+                        raise RuntimeError('test failed')
                     state.append('raised')
+                else:
+                    if value is not None:
+                        raise RuntimeError('test failed')
                 state.append('release')
 
         def func(n):
+            del state[:]
             try:
                 with C('hello') as c:
                     state.append(c.name)
-                    if n:
+                    if n == 1:
                         raise ValueError
-            except ValueError:
+                    elif n == 2:
+                        raise TypeError
+            except (ValueError, TypeError):
                 pass
             return ', '.join(state)
         f = self.getcompiled(func, [int])
+        res = f(0)
+        assert res == 'acquire, hello, release'
         res = f(1)
         assert res == 'acquire, hello, raised, release'
-
+        res = f(2)
+        assert res == 'acquire, hello, raised, release'



More information about the Pypy-commit mailing list