Merge 3.6 (issue #28843)

This commit is contained in:
Yury Selivanov 2016-12-01 11:37:47 -05:00
parent 4778eab1f2
commit edfe8869c8
2 changed files with 20 additions and 0 deletions

View File

@ -1952,6 +1952,21 @@ class BaseTaskTests:
self.assertFalse(gather_task.cancelled()) self.assertFalse(gather_task.cancelled())
self.assertEqual(gather_task.result(), [42]) self.assertEqual(gather_task.result(), [42])
def test_exception_traceback(self):
# See http://bugs.python.org/issue28843
@asyncio.coroutine
def foo():
1 / 0
@asyncio.coroutine
def main():
task = self.new_task(self.loop, foo())
yield # skip one loop iteration
self.assertIsNotNone(task.exception().__traceback__)
self.loop.run_until_complete(main())
@mock.patch('asyncio.base_events.logger') @mock.patch('asyncio.base_events.logger')
def test_error_in_call_soon(self, m_log): def test_error_in_call_soon(self, m_log):
def call_soon(callback, *args): def call_soon(callback, *args):

View File

@ -1041,6 +1041,8 @@ FutureIter_throw(futureiterobject *self, PyObject *args)
if (PyExceptionClass_Check(type)) { if (PyExceptionClass_Check(type)) {
PyErr_NormalizeException(&type, &val, &tb); PyErr_NormalizeException(&type, &val, &tb);
/* No need to call PyException_SetTraceback since we'll be calling
PyErr_Restore for `type`, `val`, and `tb`. */
} else if (PyExceptionInstance_Check(type)) { } else if (PyExceptionInstance_Check(type)) {
if (val) { if (val) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
@ -2001,6 +2003,9 @@ task_step_impl(TaskObj *task, PyObject *exc)
if (!ev || !PyObject_TypeCheck(ev, (PyTypeObject *) et)) { if (!ev || !PyObject_TypeCheck(ev, (PyTypeObject *) et)) {
PyErr_NormalizeException(&et, &ev, &tb); PyErr_NormalizeException(&et, &ev, &tb);
} }
if (tb != NULL) {
PyException_SetTraceback(ev, tb);
}
o = future_set_exception((FutureObj*)task, ev); o = future_set_exception((FutureObj*)task, ev);
if (!o) { if (!o) {
/* An exception in Task.set_exception() */ /* An exception in Task.set_exception() */