]> granicus.if.org Git - python/commitdiff
fix sending tuples to custom generator objects with yield from (closes #21209)
authorBenjamin Peterson <benjamin@python.org>
Mon, 14 Apr 2014 03:52:01 +0000 (23:52 -0400)
committerBenjamin Peterson <benjamin@python.org>
Mon, 14 Apr 2014 03:52:01 +0000 (23:52 -0400)
Debugged by Victor.

Lib/test/test_pep380.py
Misc/NEWS
Python/ceval.c

index 4a43b7d62b5d9b4db29a9b4c2f99afa5ef77c09b..69194df9e750a5073cbb2b46bf71209353d5803d 100644 (file)
@@ -993,6 +993,25 @@ class TestPEP380Operation(unittest.TestCase):
             del inner_gen
             gc_collect()
 
+    def test_send_tuple_with_custom_generator(self):
+        # See issue #21209.
+        class MyGen:
+            def __iter__(self):
+                return self
+            def __next__(self):
+                return 42
+            def send(self, what):
+                nonlocal v
+                v = what
+                return None
+        def outer():
+            v = yield from MyGen()
+        g = outer()
+        next(g)
+        v = None
+        g.send((1, 2, 3, 4))
+        self.assertEqual(v, (1, 2, 3, 4))
+
 
 def test_main():
     from test import support
index 6fc6e2fbd6de05451ea8a3b6cd27e0d1d46c924f..6e149686294e70f910cc3774bf30b486e50906e3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: TBA
 Core and Builtins
 -----------------
 
+- Issue #21209: Fix sending tuples to custom generator objects with the yield
+  from syntax.
+
 - Issue #21134: Fix segfault when str is called on an uninitialized
   UnicodeEncodeError, UnicodeDecodeError, or UnicodeTranslateError object.
 
index 5db88be620724c57d5ba1d7af6d1262362e87ac4..1cc3c947087e368740a91c8581b04081ecd772ab 100644 (file)
@@ -1902,7 +1902,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
                 if (v == Py_None)
                     retval = Py_TYPE(reciever)->tp_iternext(reciever);
                 else
-                    retval = _PyObject_CallMethodId(reciever, &PyId_send, "O", v);
+                    retval = _PyObject_CallMethodIdObjArgs(reciever, &PyId_send, v, NULL);
             }
             Py_DECREF(v);
             if (retval == NULL) {