_, result = run_async(g())
self.assertIsNone(result.__context__)
+ def test_await_17(self):
+ # See https://github.com/python/cpython/issues/131666 for details.
+ class A:
+ async def __anext__(self):
+ raise StopAsyncIteration
+ def __aiter__(self):
+ return self
+
+ anext_awaitable = anext(A(), "a").__await__()
+ self.assertRaises(TypeError, anext_awaitable.close, 1)
+
def test_with_1(self):
class Manager:
def __init__(self, name):
if (awaitable == NULL) {
return NULL;
}
- // 'arg' may be a tuple (if coming from a METH_VARARGS method)
- // or a single object (if coming from a METH_O method).
- PyObject *ret = PyObject_CallMethod(awaitable, meth, "O", arg);
+ // When specified, 'arg' may be a tuple (if coming from a METH_VARARGS
+ // method) or a single object (if coming from a METH_O method).
+ PyObject *ret = arg == NULL
+ ? PyObject_CallMethod(awaitable, meth, NULL)
+ : PyObject_CallMethod(awaitable, meth, "O", arg);
Py_DECREF(awaitable);
if (ret != NULL) {
return ret;
static PyObject *
-anextawaitable_close(PyObject *op, PyObject *args)
+anextawaitable_close(PyObject *op, PyObject *Py_UNUSED(dummy))
{
anextawaitableobject *obj = anextawaitableobject_CAST(op);
- return anextawaitable_proxy(obj, "close", args);
+ return anextawaitable_proxy(obj, "close", NULL);
}
static PyMethodDef anextawaitable_methods[] = {
{"send", anextawaitable_send, METH_O, send_doc},
{"throw", anextawaitable_throw, METH_VARARGS, throw_doc},
- {"close", anextawaitable_close, METH_VARARGS, close_doc},
+ {"close", anextawaitable_close, METH_NOARGS, close_doc},
{NULL, NULL} /* Sentinel */
};