From 890fed0e9c8787f4ed7eaec7608753f3e7e24d52 Mon Sep 17 00:00:00 2001 From: Thomas Kowalski Date: Mon, 27 Apr 2026 18:13:19 +0200 Subject: [PATCH 1/2] fix: properly pass array_hook to json.loads --- Lib/json/__init__.py | 2 +- Lib/test/test_json/test_decode.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/json/__init__.py b/Lib/json/__init__.py index 251025efac14b8..a48ece1c1e6c7b 100644 --- a/Lib/json/__init__.py +++ b/Lib/json/__init__.py @@ -306,7 +306,7 @@ def load(fp, *, cls=None, object_hook=None, parse_float=None, cls=cls, object_hook=object_hook, parse_float=parse_float, parse_int=parse_int, parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, - array_hook=None, **kw) + array_hook=array_hook, **kw) def loads(s, *, cls=None, object_hook=None, parse_float=None, diff --git a/Lib/test/test_json/test_decode.py b/Lib/test/test_json/test_decode.py index d846c8af7ec434..1d51fb2de0e69e 100644 --- a/Lib/test/test_json/test_decode.py +++ b/Lib/test/test_json/test_decode.py @@ -87,6 +87,13 @@ def test_array_hook(self): self.assertEqual(self.loads('[]', array_hook=tuple), ()) + def test_load_array_hook(self): + # json.load must forward array_hook to loads + fp = StringIO('[10, 20, 30]') + result = self.json.load(fp, array_hook=tuple) + self.assertEqual(result, (10, 20, 30)) + self.assertEqual(type(result), tuple) + def test_decoder_optimizations(self): # Several optimizations were made that skip over calls to # the whitespace regex, so this test is designed to try and From d77afb2a21f37f1714912f7b2178e72397dd1045 Mon Sep 17 00:00:00 2001 From: Thomas Kowalski Date: Wed, 29 Apr 2026 10:10:51 +0200 Subject: [PATCH 2/2] misc: add news entry --- .../next/Library/2026-04-29-08-10-17.gh-issue-149056.jnaD4W.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-04-29-08-10-17.gh-issue-149056.jnaD4W.rst diff --git a/Misc/NEWS.d/next/Library/2026-04-29-08-10-17.gh-issue-149056.jnaD4W.rst b/Misc/NEWS.d/next/Library/2026-04-29-08-10-17.gh-issue-149056.jnaD4W.rst new file mode 100644 index 00000000000000..0026d02c876257 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-04-29-08-10-17.gh-issue-149056.jnaD4W.rst @@ -0,0 +1,2 @@ +Fix :func:`json.load` not forwarding the *array_hook* argument to +:func:`json.loads`. Patch by Thomas Kowalski.