diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-08-20-04-04-39.gh-issue-130821.wwb_7S.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-20-04-04-39.gh-issue-130821.wwb_7S.rst new file mode 100644 index 00000000000000..d89ed1cbb30f16 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-20-04-04-39.gh-issue-130821.wwb_7S.rst @@ -0,0 +1 @@ +Include the type name in the :exc:`TypeError` raised when ``items()`` returns a non-iterable during abstract method computation in :mod:`abc`. Patch by Jason Mak. diff --git a/Modules/_abc.c b/Modules/_abc.c index 5826efbfecb690..4d87681272c5df 100644 --- a/Modules/_abc.c +++ b/Modules/_abc.c @@ -383,10 +383,14 @@ compute_abstract_methods(PyObject *self) } assert(PyList_Check(items)); for (Py_ssize_t pos = 0; pos < PyList_GET_SIZE(items); pos++) { - PyObject *it = PySequence_Fast( - PyList_GET_ITEM(items, pos), - "items() returned non-iterable"); + PyObject *item_obj = PyList_GET_ITEM(items, pos); + PyObject *it = PySequence_Fast(item_obj, "items() returned non-iterable"); if (!it) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) { + PyErr_Format(PyExc_TypeError, + "items() returned non-iterable (type %T)", + item_obj); + } goto error; } if (PySequence_Fast_GET_SIZE(it) != 2) {