From 32deaa9e09aa6687f85162bfeb8bebda7f529f64 Mon Sep 17 00:00:00 2001 From: Jason Mak Date: Thu, 20 Aug 2026 10:22:25 +0800 Subject: [PATCH 1/7] gh-130821: Add type info to error message in Modules/_abc.c Closes gh-130821 This PR updates the error message format in `Modules/_abc.c` to include the actual returned type information, matching the new consistent formatting standard requested by the core team. --- Modules/_abc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Modules/_abc.c b/Modules/_abc.c index 5826efbfecb6901..242bd39907de5f0 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, NULL); if (!it) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) { + PyErr_Format(PyExc_TypeError, + "items() returned non-iterable (type %.200s)", + Py_TYPE(item_obj)->tp_name); + } goto error; } if (PySequence_Fast_GET_SIZE(it) != 2) { From 9dc6c5d66a36ad8d794d6b37bb3c0918788d315d Mon Sep 17 00:00:00 2001 From: Jason Mak Date: Thu, 20 Aug 2026 11:54:19 +0800 Subject: [PATCH 2/7] gh-130821: Refactor _abc.c error message to use standard %T --- Modules/_abc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_abc.c b/Modules/_abc.c index 242bd39907de5f0..05f22fcf615a459 100644 --- a/Modules/_abc.c +++ b/Modules/_abc.c @@ -384,12 +384,12 @@ compute_abstract_methods(PyObject *self) assert(PyList_Check(items)); for (Py_ssize_t pos = 0; pos < PyList_GET_SIZE(items); pos++) { PyObject *item_obj = PyList_GET_ITEM(items, pos); - PyObject *it = PySequence_Fast(item_obj, NULL); + 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 %.200s)", - Py_TYPE(item_obj)->tp_name); + "items() returned non-iterable (type %T)",S + item_obj); } goto error; } From 4fc5bba963b009eae900ccbddaf66500e84cc551 Mon Sep 17 00:00:00 2001 From: Jason Mak Date: Thu, 20 Aug 2026 12:01:25 +0800 Subject: [PATCH 3/7] gh-130821: Fix syntax typo in Modules/_abc.c error message --- Modules/_abc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_abc.c b/Modules/_abc.c index 05f22fcf615a459..4d87681272c5df8 100644 --- a/Modules/_abc.c +++ b/Modules/_abc.c @@ -388,7 +388,7 @@ compute_abstract_methods(PyObject *self) if (!it) { if (PyErr_ExceptionMatches(PyExc_TypeError)) { PyErr_Format(PyExc_TypeError, - "items() returned non-iterable (type %T)",S + "items() returned non-iterable (type %T)", item_obj); } goto error; From 6eb78a5daa75a65c7ff1a9a60141d006a6c31262 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 20 Aug 2026 04:04:41 +0000 Subject: [PATCH 4/7] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-08-20-04-04-39.gh-issue-130821.wwb_7S.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-08-20-04-04-39.gh-issue-130821.wwb_7S.rst 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 000000000000000..0d90ec1cbe10563 --- /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,3 @@ +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. From 9864271a1344f627035499b78f73a830d51070b5 Mon Sep 17 00:00:00 2001 From: Jason Mak Date: Thu, 20 Aug 2026 12:27:14 +0800 Subject: [PATCH 5/7] Fix mixed line endings in NEWS entry --- .../2026-08-20-04-04-39.gh-issue-130821.wwb_7S.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 0d90ec1cbe10563..0c364e4d5916cca 100644 --- 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 @@ -1,3 +1,3 @@ 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. +Jason Mak. From 4c086eea4c90f1b935d9aab5635901f9f179c90c Mon Sep 17 00:00:00 2001 From: Jason Mak Date: Thu, 20 Aug 2026 12:30:09 +0800 Subject: [PATCH 6/7] Delete Misc/NEWS.d/next/Core_and_Builtins/2026-08-20-04-04-39.gh-issue-130821.wwb_7S.rst --- .../2026-08-20-04-04-39.gh-issue-130821.wwb_7S.rst | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-08-20-04-04-39.gh-issue-130821.wwb_7S.rst 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 deleted file mode 100644 index 0c364e4d5916cca..000000000000000 --- a/Misc/NEWS.d/next/Core_and_Builtins/2026-08-20-04-04-39.gh-issue-130821.wwb_7S.rst +++ /dev/null @@ -1,3 +0,0 @@ -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. From 190175d139e308037daaa76bfc216f97f642e918 Mon Sep 17 00:00:00 2001 From: Jason Mak Date: Thu, 20 Aug 2026 12:32:17 +0800 Subject: [PATCH 7/7] Enhance TypeError message for non-iterable items() This change includes the type name in the TypeError raised when items() returns a non-iterable during abstract method computation in the abc module. --- .../2026-08-20-04-04-39.gh-issue-130821.wwb_7S.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-08-20-04-04-39.gh-issue-130821.wwb_7S.rst 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 000000000000000..d89ed1cbb30f162 --- /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.