mirror of
https://github.com/python/cpython.git
synced 2025-10-22 14:42:22 +00:00
fix sending tuples to custom generator objects with yield from (closes #21209)
Debugged by Victor.
This commit is contained in:
parent
584f5cbf16
commit
f6e50b4a81
3 changed files with 23 additions and 1 deletions
|
@ -993,6 +993,25 @@ class TestPEP380Operation(unittest.TestCase):
|
||||||
del inner_gen
|
del inner_gen
|
||||||
gc_collect()
|
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():
|
def test_main():
|
||||||
from test import support
|
from test import support
|
||||||
|
|
|
@ -10,6 +10,9 @@ Release date: TBA
|
||||||
Core and Builtins
|
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
|
- Issue #21134: Fix segfault when str is called on an uninitialized
|
||||||
UnicodeEncodeError, UnicodeDecodeError, or UnicodeTranslateError object.
|
UnicodeEncodeError, UnicodeDecodeError, or UnicodeTranslateError object.
|
||||||
|
|
||||||
|
|
|
@ -1902,7 +1902,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
||||||
if (v == Py_None)
|
if (v == Py_None)
|
||||||
retval = Py_TYPE(reciever)->tp_iternext(reciever);
|
retval = Py_TYPE(reciever)->tp_iternext(reciever);
|
||||||
else
|
else
|
||||||
retval = _PyObject_CallMethodId(reciever, &PyId_send, "O", v);
|
retval = _PyObject_CallMethodIdObjArgs(reciever, &PyId_send, v, NULL);
|
||||||
}
|
}
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
if (retval == NULL) {
|
if (retval == NULL) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue