mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
Merge 3.6 (issue #28492)
This commit is contained in:
commit
3ceee7b0da
2 changed files with 32 additions and 2 deletions
|
@ -464,6 +464,19 @@ class FutureTests(test_utils.TestCase):
|
||||||
futures._set_result_unless_cancelled(fut, 2)
|
futures._set_result_unless_cancelled(fut, 2)
|
||||||
self.assertTrue(fut.cancelled())
|
self.assertTrue(fut.cancelled())
|
||||||
|
|
||||||
|
def test_future_stop_iteration_args(self):
|
||||||
|
fut = asyncio.Future(loop=self.loop)
|
||||||
|
fut.set_result((1, 2))
|
||||||
|
fi = fut.__iter__()
|
||||||
|
result = None
|
||||||
|
try:
|
||||||
|
fi.send(None)
|
||||||
|
except StopIteration as ex:
|
||||||
|
result = ex.args[0]
|
||||||
|
else:
|
||||||
|
self.fail('StopIteration was expected')
|
||||||
|
self.assertEqual(result, (1, 2))
|
||||||
|
|
||||||
|
|
||||||
class FutureDoneCallbackTests(test_utils.TestCase):
|
class FutureDoneCallbackTests(test_utils.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -787,9 +787,26 @@ FutureIter_iternext(futureiterobject *it)
|
||||||
|
|
||||||
res = FutureObj_result(fut, NULL);
|
res = FutureObj_result(fut, NULL);
|
||||||
if (res != NULL) {
|
if (res != NULL) {
|
||||||
// normal result
|
/* The result of the Future is not an exception.
|
||||||
PyErr_SetObject(PyExc_StopIteration, res);
|
|
||||||
|
We cunstruct an exception instance manually with
|
||||||
|
PyObject_CallFunctionObjArgs and pass it to PyErr_SetObject
|
||||||
|
(similarly to what genobject.c does).
|
||||||
|
|
||||||
|
This is to handle a situation when "res" is a tuple, in which
|
||||||
|
case PyErr_SetObject would set the value of StopIteration to
|
||||||
|
the first element of the tuple.
|
||||||
|
|
||||||
|
(See PyErr_SetObject/_PyErr_CreateException code for details.)
|
||||||
|
*/
|
||||||
|
PyObject *e = PyObject_CallFunctionObjArgs(
|
||||||
|
PyExc_StopIteration, res, NULL);
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
|
if (e == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
PyErr_SetObject(PyExc_StopIteration, e);
|
||||||
|
Py_DECREF(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
it->future = NULL;
|
it->future = NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue