Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix signature of anext_awaitable.close
  • Loading branch information
picnixz committed Mar 24, 2025
commit a4c728e6b36400ce9a6da39f5991702760b4052f
11 changes: 11 additions & 0 deletions Lib/test/test_coroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,17 @@ async def g():
_, 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this results in an unawaited coroutine warning

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed here #131708


def test_with_1(self):
class Manager:
def __init__(self, name):
Expand Down
10 changes: 6 additions & 4 deletions Objects/iterobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,9 @@ anextawaitable_proxy(anextawaitableobject *obj, char *meth, PyObject *arg) {
if (awaitable == NULL) {
return NULL;
}
PyObject *ret = PyObject_CallMethod(awaitable, meth, "O", arg);
PyObject *ret = arg == NULL
? PyObject_CallMethod(awaitable, meth, NULL)
: PyObject_CallMethod(awaitable, meth, "O", arg);
Py_DECREF(awaitable);
if (ret != NULL) {
return ret;
Expand Down Expand Up @@ -439,8 +441,8 @@ anextawaitable_throw(anextawaitableobject *obj, PyObject *arg) {


static PyObject *
anextawaitable_close(anextawaitableobject *obj, PyObject *arg) {
return anextawaitable_proxy(obj, "close", arg);
anextawaitable_close(anextawaitableobject *obj, PyObject *Py_UNUSED(dummy)) {
return anextawaitable_proxy(obj, "close", NULL);
}


Expand All @@ -466,7 +468,7 @@ PyDoc_STRVAR(close_doc,
static PyMethodDef anextawaitable_methods[] = {
{"send",(PyCFunction)anextawaitable_send, METH_O, send_doc},
{"throw",(PyCFunction)anextawaitable_throw, METH_VARARGS, throw_doc},
{"close",(PyCFunction)anextawaitable_close, METH_VARARGS, close_doc},
{"close",(PyCFunction)anextawaitable_close, METH_NOARGS, close_doc},
{NULL, NULL} /* Sentinel */
};

Expand Down