Author: Matti Picus <matti.pi...@gmail.com>
Branch: unicode-utf8-py3
Changeset: r94800:ebb1b24a3065
Date: 2018-07-01 22:43 -0500
http://bitbucket.org/pypy/pypy/changeset/ebb1b24a3065/

Log:    merge py3.5 into branch

diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1260,9 +1260,11 @@
 
     def WITH_CLEANUP_FINISH(self, oparg, next_instr):
         w_suppress = self.popvalue()
-        if self.space.is_true(w_suppress):
-            # __exit__() returned True -> Swallow the exception.
-            self.settopvalue(self.space.w_None)
+        w_unroller = self.peekvalue()
+        if isinstance(w_unroller, SApplicationException):
+            if self.space.is_true(w_suppress):
+                # __exit__() returned True -> Swallow the exception.
+                self.settopvalue(self.space.w_None)
         # this is always followed by END_FINALLY
         # in the stack now: [w_unroller-or-w_None..]
 
diff --git a/pypy/interpreter/test/test_coroutine.py 
b/pypy/interpreter/test/test_coroutine.py
--- a/pypy/interpreter/test/test_coroutine.py
+++ b/pypy/interpreter/test/test_coroutine.py
@@ -112,6 +112,27 @@
         assert seen == ['aenter', 'aexit']
         """
 
+    def test_async_with_exit_True(self): """
+        seen = []
+        class X:
+            async def __aenter__(self):
+                seen.append('aenter')
+            async def __aexit__(self, *args):
+                seen.append('aexit')
+                return True
+        async def f(x):
+            async with x:
+                return 42
+        c = f(X())
+        try:
+            c.send(None)
+        except StopIteration as e:
+            assert e.value == 42
+        else:
+            assert False, "should have raised"
+        assert seen == ['aenter', 'aexit']
+        """
+
     def test_await(self): """
         class X:
             def __await__(self):
diff --git a/pypy/interpreter/test/test_raise.py 
b/pypy/interpreter/test/test_raise.py
--- a/pypy/interpreter/test/test_raise.py
+++ b/pypy/interpreter/test/test_raise.py
@@ -309,6 +309,17 @@
                 return object()
         raises(TypeError, "raise MyException")
 
+    def test_with_exit_True(self):
+        class X:
+            def __enter__(self):
+                pass
+            def __exit__(self, *args):
+                return True
+        def g():
+            with X():
+                return 42
+            assert False, "unreachable"
+        assert g() == 42
 
     def test_pop_exception_value(self):
         # assert that this code don't crash
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to