Skip to content

Commit 3765181

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

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
@@ -241,39 +241,38 @@ Basic Usage
241241

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

248248
*object_pairs_hook* is an optional function that will be called with the
249249
result of any object literal decoded with an ordered list of pairs. The
250250
return value of *object_pairs_hook* will be used instead of the
251-
:class:`dict`. This feature can be used to implement custom decoders.
252-
If *object_hook* is also defined, the *object_pairs_hook* takes priority.
251+
:class:`dict`. This feature can be used to implement custom decoders. If
252+
*object_hook* is also defined, the *object_pairs_hook* takes priority.
253253

254254
.. versionchanged:: 3.1
255255
Added support for *object_pairs_hook*.
256256

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

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

267267
.. versionchanged:: 3.11
268268
The default *parse_int* of :func:`int` now limits the maximum length of
269269
the integer string via the interpreter's :ref:`integer string
270270
conversion length limitation <int_max_str_digits>` to help avoid denial
271271
of service attacks.
272272

273-
*parse_constant*, if specified, will be called with one of the following
274-
strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``.
275-
This can be used to raise an exception if invalid JSON numbers
276-
are encountered.
273+
*parse_constant* is an optional function that will be called with one of the
274+
following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This can be
275+
used to raise an exception if invalid JSON numbers are encountered.
277276

278277
.. versionchanged:: 3.1
279278
*parse_constant* doesn't get called on 'null', 'true', 'false' anymore.
@@ -345,34 +344,33 @@ Encoders and Decoders
345344
It also understands ``NaN``, ``Infinity``, and ``-Infinity`` as their
346345
corresponding ``float`` values, which is outside the JSON spec.
347346

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

353-
*object_pairs_hook*, if specified will be called with the result of every
354-
JSON object decoded with an ordered list of pairs. The return value of
355-
*object_pairs_hook* will be used instead of the :class:`dict`. This
356-
feature can be used to implement custom decoders. If *object_hook* is also
357-
defined, the *object_pairs_hook* takes priority.
352+
*object_pairs_hook* is an optional function that will be called with the
353+
result of every JSON object decoded with an ordered list of pairs. The
354+
return value of *object_pairs_hook* will be used instead of the
355+
:class:`dict`. This feature can be used to implement custom decoders. If
356+
*object_hook* is also defined, the *object_pairs_hook* takes priority.
358357

359358
.. versionchanged:: 3.1
360359
Added support for *object_pairs_hook*.
361360

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

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

372-
*parse_constant*, if specified, will be called with one of the following
373-
strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``.
374-
This can be used to raise an exception if invalid JSON numbers
375-
are encountered.
371+
*parse_constant* is an optional function that will be called with one of the
372+
following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This can be
373+
used to raise an exception if invalid JSON numbers are encountered.
376374

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

0 commit comments

Comments
 (0)