static PyObject *
task_step_impl(asyncio_state *state, TaskObj *task, PyObject *exc)
{
- int res;
int clear_exc = 0;
PyObject *result = NULL;
PyObject *coro;
if (task->task_must_cancel) {
assert(exc != Py_None);
- if (exc) {
- /* Check if exc is a CancelledError */
- res = PyObject_IsInstance(exc, state->asyncio_CancelledError);
- if (res == -1) {
- /* An error occurred, abort */
- goto fail;
- }
- if (res == 0) {
- /* exc is not CancelledError; reset it to NULL */
- exc = NULL;
- }
- }
-
- if (!exc) {
+ if (!exc || !PyErr_GivenExceptionMatches(exc, state->asyncio_CancelledError)) {
/* exc was not a CancelledError */
exc = create_cancelled_error(state, (FutureObj*)task);