summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-01-09 19:41:02 (GMT)
committerGitHub <noreply@github.com>2024-01-09 19:41:02 (GMT)
commit5273655bea050432756098641b9fda72361bf983 (patch)
tree6686fce4b5c591b127db6dfeb28e742b7d72a85a
parent9100fc407e8c7038e7214b600b4ae568ae5510e3 (diff)
downloadcpython-5273655bea050432756098641b9fda72361bf983.zip
cpython-5273655bea050432756098641b9fda72361bf983.tar.gz
cpython-5273655bea050432756098641b9fda72361bf983.tar.bz2
gh-113848: Use PyErr_GivenExceptionMatches() for check for CancelledError (GH-113849)
-rw-r--r--Modules/_asynciomodule.c16
1 files changed, 1 insertions, 15 deletions
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index 3a11cdc..b929e6d 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -2754,7 +2754,6 @@ gen_status_from_result(PyObject **result)
static PyObject *
task_step_impl(asyncio_state *state, TaskObj *task, PyObject *exc)
{
- int res;
int clear_exc = 0;
PyObject *result = NULL;
PyObject *coro;
@@ -2771,20 +2770,7 @@ task_step_impl(asyncio_state *state, TaskObj *task, PyObject *exc)
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);