8000 bpo-32591: _PyErr_WarnUnawaitedCoroutine() sets source (GH-19247) · python/cpython@8d84adc · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d84adc

Browse files
authored
bpo-32591: _PyErr_WarnUnawaitedCoroutine() sets source (GH-19247)
The _PyErr_WarnUnawaitedCoroutine() fallback now also sets the coroutine object as the source of the warning, as done by the Python implementation warnings._warn_unawaited_coroutine(). Moreover, don't truncate the coroutine name: Python supports arbitrary string length to format the message.
1 parent 5be8241 commit 8d84adc

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

Python/_warnings.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,23 @@ PyErr_WarnFormat(PyObject *category, Py_ssize_t stack_level,
11291129
return res;
11301130
}
11311131

1132+
static int
1133+
_PyErr_WarnFormat(PyObject *source, PyObject *category, Py_ssize_t stack_level,
1134+
const char *format, ...)
1135+
{
1136+
int res;
1137+
va_list vargs;
1138+
1139+
#ifdef HAVE_STDARG_PROTOTYPES
1140+
va_start(vargs, format);
1141+
#else
1142+
va_start(vargs);
1143+
#endif
1144+
res = _PyErr_WarnFormatV(source, category, stack_level, format, vargs);
1145+
va_end(vargs);
1146+
return res;
1147+
}
1148+
11321149
int
11331150
PyErr_ResourceWarning(PyObject *source, Py_ssize_t stack_level,
11341151
const char *format, ...)
@@ -1297,9 +1314,9 @@ _PyErr_WarnUnawaitedCoroutine(PyObject *coro)
12971314
PyErr_WriteUnraisable(coro);
12981315
}
12991316
if (!warned) {
1300-
if (PyErr_WarnFormat(PyExc_RuntimeWarning, 1,
1301-
"coroutine '%.50S' was never awaited",
1302-
((PyCoroObject *)coro)->cr_qualname) < 0)
1317+
if (_PyErr_WarnFormat(coro, PyExc_RuntimeWarning, 1,
1318+
"coroutine '%S' was never awaited",
1319+
((PyCoroObject *)coro)->cr_qualname) < 0)
13031320
{
13041321
PyErr_WriteUnraisable(coro);
13051322
}

0 commit comments

Comments
 (0)
0