Skip to content

Commit b8dc6a8

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Use improved error messages on 3.15
Summary: The error messages when getting the awaitable iter on 3.15 [have been improved](https://www.internalfb.com/code/fbsource/[6db8beaffe22afe16fa79c346432256d973b86d2]/third-party/python/main/pristine/Objects/genobject.c?lines=1097) - this is just duplicating the new messages. Reviewed By: martindemello Differential Revision: D85976653 fbshipit-source-id: c70ed9086fbc39e089e363ced9096f2b1954d829
1 parent f945a12 commit b8dc6a8

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

cinderx/Jit/generators_core.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,31 @@ PyObject* JitCoro_GetAwaitableIter(PyObject* o) {
6464
jit::jitgen_is_coroutine(res)) {
6565
/* __await__ must return an *iterator*, not
6666
a coroutine or another awaitable (see PEP 492) */
67-
PyErr_SetString(PyExc_TypeError, "__await__() returned a coroutine");
67+
if constexpr (PY_VERSION_HEX >= 0x030F0000) {
68+
PyErr_Format(
69+
PyExc_TypeError,
70+
"%T.__await__() must return an iterator, "
71+
"not coroutine",
72+
o);
73+
} else {
74+
PyErr_SetString(PyExc_TypeError, "__await__() returned a coroutine");
75+
}
6876
Py_CLEAR(res);
6977
} else if (!PyIter_Check(res)) {
70-
PyErr_Format(
71-
PyExc_TypeError,
72-
"__await__() returned non-iterator "
73-
"of type '%.100s'",
74-
Py_TYPE(res)->tp_name);
78+
if constexpr (PY_VERSION_HEX >= 0x030F0000) {
79+
PyErr_Format(
80+
PyExc_TypeError,
81+
"%T.__await__() must return an iterator, "
82+
"not %T",
83+
o,
84+
res);
85+
} else {
86+
PyErr_Format(
87+
PyExc_TypeError,
88+
"__await__() returned non-iterator "
89+
"of type '%.100s'",
90+
Py_TYPE(res)->tp_name);
91+
}
7592
Py_CLEAR(res);
7693
}
7794
}

0 commit comments

Comments
 (0)