Skip to content

Commit 66bd180

Browse files
serhiy-storchakaGlyphack
authored andcommitted
pythongh-113848: Use PyErr_GivenExceptionMatches() for check for CancelledError (pythonGH-113849)
1 parent 5e7b47e commit 66bd180

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

Modules/_asynciomodule.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2754,7 +2754,6 @@ gen_status_from_result(PyObject **result)
27542754
static PyObject *
27552755
task_step_impl(asyncio_state *state, TaskObj *task, PyObject *exc)
27562756
{
2757-
int res;
27582757
int clear_exc = 0;
27592758
PyObject *result = NULL;
27602759
PyObject *coro;
@@ -2771,20 +2770,7 @@ task_step_impl(asyncio_state *state, TaskObj *task, PyObject *exc)
27712770
if (task->task_must_cancel) {
27722771
assert(exc != Py_None);
27732772

2774-
if (exc) {
2775-
/* Check if exc is a CancelledError */
2776-
res = PyObject_IsInstance(exc, state->asyncio_CancelledError);
2777-
if (res == -1) {
2778-
/* An error occurred, abort */
2779-
goto fail;
2780-
}
2781-
if (res == 0) {
2782-
/* exc is not CancelledError; reset it to NULL */
2783-
exc = NULL;
2784-
}
2785-
}
2786-
2787-
if (!exc) {
2773+
if (!exc || !PyErr_GivenExceptionMatches(exc, state->asyncio_CancelledError)) {
27882774
/* exc was not a CancelledError */
27892775
exc = create_cancelled_error(state, (FutureObj*)task);
27902776

0 commit comments

Comments
 (0)