diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-12-29-16-55-12.gh-issue-113566.grGQEg.rst b/Misc/NEWS.d/next/Core and Builtins/2023-12-29-16-55-12.gh-issue-113566.grGQEg.rst new file mode 100644 index 00000000000000..7c22afad446990 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-12-29-16-55-12.gh-issue-113566.grGQEg.rst @@ -0,0 +1,2 @@ +Fix a 3.11-specific crash when the ``repr`` of a :class:`~asyncio.Future` is +requested after the module has already been garbage-collected. diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index b2fef017050b22..a92feebcdbc4ac 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -1377,6 +1377,9 @@ static PyObject * FutureObj_repr(FutureObj *fut) { ENSURE_FUTURE_ALIVE(fut) + if (asyncio_future_repr_func == NULL) { + return PyUnicode_FromFormat("", fut); + } return PyObject_CallOneArg(asyncio_future_repr_func, (PyObject *)fut); }