Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6e50b4

Browse files
committed
fix sending tuples to custom generator objects with yield from (closes #21209)
Debugged by Victor.
1 parent 584f5cb commit f6e50b4

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

Lib/test/test_pep380.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,25 @@ def outer():
993993
del inner_gen
994994
gc_collect()
995995

996+
def test_send_tuple_with_custom_generator(self):
997+
# See issue #21209.
998+
class MyGen:
999+
def __iter__(self):
1000+
return self
1001+
def __next__(self):
1002+
return 42
1003+
def send(self, what):
1004+
nonlocal v
1005+
v = what
1006+
return None
1007+
def outer():
1008+
v = yield from MyGen()
1009+
g = outer()
1010+
next(g)
1011+
v = None
1012+
g.send((1, 2, 3, 4))
1013+
self.assertEqual(v, (1, 2, 3, 4))
1014+
9961015

9971016
def test_main():
9981017
from test import support

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: TBA
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #21209: Fix sending tuples to custom generator objects with the yield
14+
from syntax.
15+
1316
- Issue #21134: Fix segfault when str is called on an uninitialized
1417
UnicodeEncodeError, UnicodeDecodeError, or UnicodeTranslateError object.
1518

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
19021902
if (v == Py_None)
19031903
retval = Py_TYPE(reciever)->tp_iternext(reciever);
19041904
else
1905-
retval = _PyObject_CallMethodId(reciever, &PyId_send, "O", v);
1905+
retval = _PyObject_CallMethodIdObjArgs(reciever, &PyId_send, v, NULL);
19061906
}
19071907
Py_DECREF(v);
19081908
if (retval == NULL) {

0 commit comments

Comments
 (0)