Skip to content

Commit c3a866c

Browse files
[3.12] pythongh-123392: Clarify wording regarding parameters that are functions to be called (pythonGH-123394) (pythonGH-123665)
(cherry picked from commit c08ede2) Co-authored-by: ryan-duve <ryan-duve@users.noreply.github.com>
1 parent a0c9f51 commit c3a866c

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

Doc/library/json.rst

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -230,39 +230,38 @@ Basic Usage
230230

231231
*object_hook* is an optional function that will be called with the result of
232232
any object literal decoded (a :class:`dict`). The return value of
233-
*object_hook* will be used instead of the :class:`dict`. This feature can be used
234-
to implement custom decoders (e.g. `JSON-RPC <https://www.jsonrpc.org>`_
235-
class hinting).
233+
*object_hook* will be used instead of the :class:`dict`. This feature can
234+
be used to implement custom decoders (e.g. `JSON-RPC
235+
<https://www.jsonrpc.org>`_ class hinting).
236236

237237
*object_pairs_hook* is an optional function that will be called with the
238238
result of any object literal decoded with an ordered list of pairs. The
239239
return value of *object_pairs_hook* will be used instead of the
240-
:class:`dict`. This feature can be used to implement custom decoders.
241-
If *object_hook* is also defined, the *object_pairs_hook* takes priority.
240+
:class:`dict`. This feature can be used to implement custom decoders. If
241+
*object_hook* is also defined, the *object_pairs_hook* takes priority.
242242

243243
.. versionchanged:: 3.1
244244
Added support for *object_pairs_hook*.
245245

246-
*parse_float*, if specified, will be called with the string of every JSON
247-
float to be decoded. By default, this is equivalent to ``float(num_str)``.
248-
This can be used to use another datatype or parser for JSON floats
249-
(e.g. :class:`decimal.Decimal`).
246+
*parse_float* is an optional function that will be called with the string of
247+
every JSON float to be decoded. By default, this is equivalent to
248+
``float(num_str)``. This can be used to use another datatype or parser for
249+
JSON floats (e.g. :class:`decimal.Decimal`).
250250

251-
*parse_int*, if specified, will be called with the string of every JSON int
252-
to be decoded. By default, this is equivalent to ``int(num_str)``. This can
253-
be used to use another datatype or parser for JSON integers
254-
(e.g. :class:`float`).
251+
*parse_int* is an optional function that will be called with the string of
252+
every JSON int to be decoded. By default, this is equivalent to
253+
``int(num_str)``. This can be used to use another datatype or parser for
254+
JSON integers (e.g. :class:`float`).
255255

256256
.. versionchanged:: 3.11
257257
The default *parse_int* of :func:`int` now limits the maximum length of
258258
the integer string via the interpreter's :ref:`integer string
259259
conversion length limitation <int_max_str_digits>` to help avoid denial
260260
of service attacks.
261261

262-
*parse_constant*, if specified, will be called with one of the following
263-
strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``.
264-
This can be used to raise an exception if invalid JSON numbers
265-
are encountered.
262+
*parse_constant* is an optional function that will be called with one of the
263+
following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This can be
264+
used to raise an exception if invalid JSON numbers are encountered.
266265

267266
.. versionchanged:: 3.1
268267
*parse_constant* doesn't get called on 'null', 'true', 'false' anymore.
@@ -334,34 +333,33 @@ Encoders and Decoders
334333
It also understands ``NaN``, ``Infinity``, and ``-Infinity`` as their
335334
corresponding ``float`` values, which is outside the JSON spec.
336335

337-
*object_hook*, if specified, will be called with the result of every JSON
338-
object decoded and its return value will be used in place of the given
339-
:class:`dict`. This can be used to provide custom deserializations (e.g. to
340-
support `JSON-RPC <https://www.jsonrpc.org>`_ class hinting).
336+
*object_hook* is an optional function that will be called with the result of
337+
every JSON object decoded and its return value will be used in place of the
338+
given :class:`dict`. This can be used to provide custom deserializations
339+
(e.g. to support `JSON-RPC <https://www.jsonrpc.org>`_ class hinting).
341340

342-
*object_pairs_hook*, if specified will be called with the result of every
343-
JSON object decoded with an ordered list of pairs. The return value of
344-
*object_pairs_hook* will be used instead of the :class:`dict`. This
345-
feature can be used to implement custom decoders. If *object_hook* is also
346-
defined, the *object_pairs_hook* takes priority.
341+
*object_pairs_hook* is an optional function that will be called with the
342+
result of every JSON object decoded with an ordered list of pairs. The
343+
return value of *object_pairs_hook* will be used instead of the
344+
:class:`dict`. This feature can be used to implement custom decoders. If
345+
*object_hook* is also defined, the *object_pairs_hook* takes priority.
347346

348347
.. versionchanged:: 3.1
349348
Added support for *object_pairs_hook*.
350349

351-
*parse_float*, if specified, will be called with the string of every JSON
352-
float to be decoded. By default, this is equivalent to ``float(num_str)``.
353-
This can be used to use another datatype or parser for JSON floats
354-
(e.g. :class:`decimal.Decimal`).
350+
*parse_float* is an optional function that will be called with the string of
351+
every JSON float to be decoded. By default, this is equivalent to
352+
``float(num_str)``. This can be used to use another datatype or parser for
353+
JSON floats (e.g. :class:`decimal.Decimal`).
355354

356-
*parse_int*, if specified, will be called with the string of every JSON int
357-
to be decoded. By default, this is equivalent to ``int(num_str)``. This can
358-
be used to use another datatype or parser for JSON integers
359-
(e.g. :class:`float`).
355+
*parse_int* is an optional function that will be called with the string of
356+
every JSON int to be decoded. By default, this is equivalent to
357+
``int(num_str)``. This can be used to use another datatype or parser for
358+
JSON integers (e.g. :class:`float`).
360359

361-
*parse_constant*, if specified, will be called with one of the following
362-
strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``.
363-
This can be used to raise an exception if invalid JSON numbers
364-
are encountered.
360+
*parse_constant* is an optional function that will be called with one of the
361+
following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This can be
362+
used to raise an exception if invalid JSON numbers are encountered.
365363

366364
If *strict* is false (``True`` is the default), then control characters
367365
will be allowed inside strings. Control characters in this context are

0 commit comments

Comments
 (0)