@@ -69,6 +69,7 @@ static PyObject * unicode_concatenate(PyObject *, PyObject *,
6969static PyObject * special_lookup (PyObject * , _Py_Identifier * );
7070static int check_args_iterable (PyObject * func , PyObject * vararg );
7171static void format_kwargs_mapping_error (PyObject * func , PyObject * kwargs );
72+ static void format_awaitable_error (PyTypeObject * , int );
7273
7374#define NAME_ERROR_MSG \
7475 "name '%.200s' is not defined"
@@ -1736,6 +1737,11 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
17361737 PyObject * iterable = TOP ();
17371738 PyObject * iter = _PyCoro_GetAwaitableIter (iterable );
17381739
1740+ if (iter == NULL ) {
1741+ format_awaitable_error (Py_TYPE (iterable ),
1742+ _Py_OPCODE (next_instr [-2 ]));
1743+ }
1744+
17391745 Py_DECREF (iterable );
17401746
17411747 if (iter != NULL && PyCoro_CheckExact (iter )) {
@@ -4985,6 +4991,25 @@ format_exc_unbound(PyCodeObject *co, int oparg)
49854991 }
49864992}
49874993
4994+ static void
4995+ format_awaitable_error (PyTypeObject * type , int prevopcode )
4996+ {
4997+ if (type -> tp_as_async == NULL || type -> tp_as_async -> am_await == NULL ) {
4998+ if (prevopcode == BEFORE_ASYNC_WITH ) {
4999+ PyErr_Format (PyExc_TypeError ,
5000+ "'async with' received an object from __aenter__ "
5001+ "that does not implement __await__: %.100s" ,
5002+ type -> tp_name );
5003+ }
5004+ else if (prevopcode == WITH_CLEANUP_START ) {
5005+ PyErr_Format (PyExc_TypeError ,
5006+ "'async with' received an object from __aexit__ "
5007+ "that does not implement __await__: %.100s" ,
5008+ type -> tp_name );
5009+ }
5010+ }
5011+ }
5012+
49885013static PyObject *
49895014unicode_concatenate (PyObject * v , PyObject * w ,
49905015 PyFrameObject * f , const _Py_CODEUNIT * next_instr )
0 commit comments