Author: Armin Rigo <ar...@tunes.org>
Branch: py3.5-corowrapper
Changeset: r87147:363825d9fe26
Date: 2016-09-16 19:24 +0200
http://bitbucket.org/pypy/pypy/changeset/363825d9fe26/

Log:    pass test_generator

diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -188,11 +188,8 @@
                 w_retval = w_yf.send_ex(w_inputvalue_or_err)
             elif space.is_w(w_inputvalue_or_err, space.w_None):
                 w_retval = space.next(w_yf)
-            elif isinstance(w_inputvalue_or_err, SApplicationException):
-                operr = w_inputvalue_or_err.operr
-                XXXXX
             else:
-                w_retval = space.call_method(w_yf, "send", w_inputvalue_or_err)
+                w_retval = delegate_to_nongen(space, w_yf, w_inputvalue_or_err)
         except OperationError as e:
             self.w_yielded_from = None
             if not e.match(space, space.w_StopIteration):
@@ -430,6 +427,27 @@
         else:
             space.call_function(w_close)
 
+def delegate_to_nongen(space, w_yf, w_inputvalue_or_err):
+    # invoke a "send" or "throw" by method name to a non-generator w_yf
+    if isinstance(w_inputvalue_or_err, SApplicationException):
+        operr = w_inputvalue_or_err.operr
+        try:
+            w_meth = space.getattr(w_yf, space.wrap("throw"))
+        except OperationError as e:
+            if not e.match(space, space.w_AttributeError):
+                raise
+            raise operr
+        # bah, CPython calls here with the exact same arguments as
+        # originally passed to throw().  In our case it is far removed.
+        # Let's hope nobody will complain...
+        operr.normalize_exception(space)
+        w_exc = operr.w_type
+        w_val = operr.get_w_value(space)
+        w_tb  = space.wrap(operr.get_traceback())
+        return space.call_function(w_meth, w_exc, w_val, w_tb)
+    else:
+        return space.call_method(w_yf, "send", w_inputvalue_or_err)
+
 
 def get_printable_location_genentry(bytecode):
     return '%s <generator>' % (bytecode.get_repr(),)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to