Author: Armin Rigo <[email protected]>
Branch: py3.6
Changeset: r91884:2d1ce02f13b7
Date: 2017-07-16 11:48 +0200
http://bitbucket.org/pypy/pypy/changeset/2d1ce02f13b7/

Log:    in-progress

diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -380,6 +380,12 @@
             _break_context_cycle(space, w_value, w_context)
             space.setattr(w_value, space.newtext('__context__'), w_context)
 
+    def chain_exceptions_from_cause(self, space, exception):
+        # XXX does this code really make sense?
+        self.chain_exceptions(space, exception)
+        self.set_cause(space, exception.get_w_value(space))
+        self.record_context(space, space.getexecutioncontext())
+
     # A simplified version of _PyErr_TrySetFromCause, which returns a
     # new exception of the same class, but with another error message.
     # This only works for exceptions which have just a single message,
diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -129,6 +129,9 @@
             try:
                 if e.match(space, space.w_StopIteration):
                     self._leak_stopiteration(e)
+                elif (isinstance(self, AsyncGenerator) and
+                      e.match(space, space.w_StopAsyncIteration)):
+                    self._leak_stopasynciteration(e)
             finally:
                 self.frame_is_finished()
             raise
@@ -218,14 +221,19 @@
             e2 = OperationError(space.w_RuntimeError,
                                 space.newtext("%s raised StopIteration" %
                                               self.KIND))
-            e2.chain_exceptions(space, e)
-            e2.set_cause(space, e.get_w_value(space))
-            e2.record_context(space, space.getexecutioncontext())
+            e2.chain_exceptions_from_cause(space, e)
             raise e2
         else:
             space.warn(space.newunicode(u"generator '%s' raised StopIteration"
                                         % self.get_qualname()),
-                       space.w_PendingDeprecationWarning)
+                       space.w_DeprecationWarning)
+
+    def _leak_stopasynciteration(self, e):
+        space = self.space
+        e2 = OperationError(space.w_RuntimeError,
+                   space.newtext("async generator raised StopAsyncIteration"))
+        e2.chain_exceptions_from_cause(space, e)
+        raise e2
 
     def descr_throw(self, w_type, w_val=None, w_tb=None):
         """throw(typ[,val[,tb]]) -> raise exception in generator/coroutine,
@@ -469,7 +477,7 @@
 def gen_close_iter(space, w_yf):
     # This helper function is used by close() and throw() to
     # close a subiterator being delegated to by yield-from.
-    if isinstance(w_yf, GeneratorIterator):
+    if isinstance(w_yf, GeneratorIterator) or isinstance(w_yf, Coroutine):
         w_yf.descr_close()
     else:
         try:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to