From 92d3f1a6adfd63382616061f0e1a886fa42b45e9 Mon Sep 17 00:00:00 2001 From: andrewloux Date: Thu, 12 Feb 2026 19:05:03 -0500 Subject: [PATCH 1/2] gh-140009: Use PyTuple_FromArray in _json object_pairs_hook path --- Modules/_json.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/_json.c b/Modules/_json.c index c7e62c4fe55c64..8189df81576dcc 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -806,7 +806,8 @@ _parse_object_unicode(PyScannerObject *s, PyObject *memo, PyObject *pystr, Py_ss goto bail; if (has_pairs_hook) { - PyObject *item = PyTuple_Pack(2, key, val); + PyObject *items[] = {key, val}; + PyObject *item = PyTuple_FromArray(items, 2); if (item == NULL) goto bail; Py_CLEAR(key); From 2904c9be930a0756110d73bec1169ee03e6c447b Mon Sep 17 00:00:00 2001 From: andrewloux Date: Thu, 12 Feb 2026 22:07:06 -0500 Subject: [PATCH 2/2] gh-140009: Add news entry for json object_pairs_hook optimization --- .../next/Library/2026-02-12-11-20-00.gh-issue-140009.json.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2026-02-12-11-20-00.gh-issue-140009.json.rst diff --git a/Misc/NEWS.d/next/Library/2026-02-12-11-20-00.gh-issue-140009.json.rst b/Misc/NEWS.d/next/Library/2026-02-12-11-20-00.gh-issue-140009.json.rst new file mode 100644 index 00000000000000..08fe44d66f8938 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-02-12-11-20-00.gh-issue-140009.json.rst @@ -0,0 +1 @@ +Optimize :mod:`json` decoding with ``object_pairs_hook`` by using :c:func:`PyTuple_FromArray` instead of :c:func:`PyTuple_Pack`.