Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Victor Stinner <[email protected]>
  • Loading branch information
vstinner authored Mar 27, 2026
commit 8ea13ffea8550ec527417e1c8095ef103d49dfb4
8 changes: 4 additions & 4 deletions Lib/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ def detect_encoding(b):


def load(fp, *, cls=None, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, object_pairs_hook=None,
array_hook=None, **kw):
parse_int=None, parse_constant=None, object_pairs_hook=None,
array_hook=None, **kw):
"""Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
a JSON document) to a Python object.

Expand Down Expand Up @@ -310,8 +310,8 @@ def load(fp, *, cls=None, object_hook=None, parse_float=None,


def loads(s, *, cls=None, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, object_pairs_hook=None,
array_hook=None, **kw):
parse_int=None, parse_constant=None, object_pairs_hook=None,
array_hook=None, **kw):
"""Deserialize ``s`` (a ``str``, ``bytes`` or ``bytearray`` instance
containing a JSON document) to a Python object.

Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_json/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def test_array_hook(self):
t = self.loads(s, array_hook=tuple)
self.assertEqual(t, (1, 2, 3))
self.assertEqual(type(t), tuple)

# Nested array in inner structure with object_hook
Comment thread
vstinner marked this conversation as resolved.
s = '{"xkd": [[1], [2], [3]]}'
p = frozendict(xkd=((1,), (2,), (3,)))
Expand All @@ -83,6 +84,7 @@ def test_array_hook(self):
self.assertEqual(type(data["xkd"]), tuple)
for item in data["xkd"]:
self.assertEqual(type(item), tuple)

self.assertEqual(self.loads('[]', array_hook=tuple), ())
Comment thread
jsbueno marked this conversation as resolved.
Comment thread
vstinner marked this conversation as resolved.

def test_decoder_optimizations(self):
Expand Down
3 changes: 2 additions & 1 deletion Modules/_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,8 +1270,9 @@ scanner_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (s->object_pairs_hook == NULL)
goto bail;
s->array_hook = PyObject_GetAttrString(ctx, "array_hook");
if (s->array_hook == NULL)
if (s->array_hook == NULL) {
goto bail;
}
s->parse_float = PyObject_GetAttrString(ctx, "parse_float");
if (s->parse_float == NULL)
goto bail;
Expand Down
Loading