Skip to content

Commit a754823

Browse files
agronholm1st1
authored andcommitted
Fixed inconsistency in string handling in the Task C implementation (GH-8717)
1 parent 22d131a commit a754823

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

Modules/_asynciomodule.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,7 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
19761976

19771977
if (name == Py_None) {
19781978
name = PyUnicode_FromFormat("Task-%" PRIu64, ++task_name_counter);
1979-
} else if (!PyUnicode_Check(name)) {
1979+
} else if (!PyUnicode_CheckExact(name)) {
19801980
name = PyObject_Str(name);
19811981
} else {
19821982
Py_INCREF(name);
@@ -2343,12 +2343,16 @@ static PyObject *
23432343
_asyncio_Task_set_name(TaskObj *self, PyObject *value)
23442344
/*[clinic end generated code: output=138a8d51e32057d6 input=a8359b6e65f8fd31]*/
23452345
{
2346-
PyObject *name = PyObject_Str(value);
2347-
if (name == NULL) {
2348-
return NULL;
2346+
if (!PyUnicode_CheckExact(value)) {
2347+
value = PyObject_Str(value);
2348+
if (value == NULL) {
2349+
return NULL;
2350+
}
2351+
} else {
2352+
Py_INCREF(value);
23492353
}
23502354

2351-
Py_XSETREF(self->task_name, name);
2355+
Py_XSETREF(self->task_name, value);
23522356
Py_RETURN_NONE;
23532357
}
23542358

0 commit comments

Comments
 (0)