Skip to content

Commit f87d960

Browse files
gh-149056: Properly pass array_hook in json.load() to json.loads() (GH-149057)
1 parent 779694f commit f87d960

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

Lib/json/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def load(fp, *, cls=None, object_hook=None, parse_float=None,
307307
cls=cls, object_hook=object_hook,
308308
parse_float=parse_float, parse_int=parse_int,
309309
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook,
310-
array_hook=None, **kw)
310+
array_hook=array_hook, **kw)
311311

312312

313313
def loads(s, *, cls=None, object_hook=None, parse_float=None,

Lib/test/test_json/test_decode.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ def test_array_hook(self):
8787

8888
self.assertEqual(self.loads('[]', array_hook=tuple), ())
8989

90+
def test_load_array_hook(self):
91+
# json.load must forward array_hook to loads
92+
fp = StringIO('[10, 20, 30]')
93+
result = self.json.load(fp, array_hook=tuple)
94+
self.assertEqual(result, (10, 20, 30))
95+
self.assertEqual(type(result), tuple)
96+
9097
def test_decoder_optimizations(self):
9198
# Several optimizations were made that skip over calls to
9299
# the whitespace regex, so this test is designed to try and
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :func:`json.load` not forwarding the *array_hook* argument to
2+
:func:`json.loads`. Patch by Thomas Kowalski.

0 commit comments

Comments
 (0)