Skip to content

Commit 0c53357

Browse files
bpo-32360: Remove object_pairs_hook=OrderedDict examples (GH-5001)
(cherry picked from commit 629338f) Co-authored-by: INADA Naoki <[email protected]>
1 parent f6d1d65 commit 0c53357

File tree

3 files changed

+11
-25
lines changed

3 files changed

+11
-25
lines changed

Doc/library/json.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,8 @@ Basic Usage
230230
*object_pairs_hook* is an optional function that will be called with the
231231
result of any object literal decoded with an ordered list of pairs. The
232232
return value of *object_pairs_hook* will be used instead of the
233-
:class:`dict`. This feature can be used to implement custom decoders that
234-
rely on the order that the key and value pairs are decoded (for example,
235-
:func:`collections.OrderedDict` will remember the order of insertion). If
236-
*object_hook* is also defined, the *object_pairs_hook* takes priority.
233+
:class:`dict`. This feature can be used to implement custom decoders.
234+
If *object_hook* is also defined, the *object_pairs_hook* takes priority.
237235

238236
.. versionchanged:: 3.1
239237
Added support for *object_pairs_hook*.
@@ -325,10 +323,8 @@ Encoders and Decoders
325323
*object_pairs_hook*, if specified will be called with the result of every
326324
JSON object decoded with an ordered list of pairs. The return value of
327325
*object_pairs_hook* will be used instead of the :class:`dict`. This
328-
feature can be used to implement custom decoders that rely on the order
329-
that the key and value pairs are decoded (for example,
330-
:func:`collections.OrderedDict` will remember the order of insertion). If
331-
*object_hook* is also defined, the *object_pairs_hook* takes priority.
326+
feature can be used to implement custom decoders. If *object_hook* is also
327+
defined, the *object_pairs_hook* takes priority.
332328

333329
.. versionchanged:: 3.1
334330
Added support for *object_pairs_hook*.

Lib/json/__init__.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
Compact encoding::
2929
3030
>>> import json
31-
>>> from collections import OrderedDict
32-
>>> mydict = OrderedDict([('4', 5), ('6', 7)])
31+
>>> mydict = {'4': 5, '6': 7}
3332
>>> json.dumps([1,2,3,mydict], separators=(',', ':'))
3433
'[1,2,3,{"4":5,"6":7}]'
3534
@@ -285,14 +284,11 @@ def load(fp, *, cls=None, object_hook=None, parse_float=None,
285284
``object_pairs_hook`` is an optional function that will be called with the
286285
result of any object literal decoded with an ordered list of pairs. The
287286
return value of ``object_pairs_hook`` will be used instead of the ``dict``.
288-
This feature can be used to implement custom decoders that rely on the
289-
order that the key and value pairs are decoded (for example,
290-
collections.OrderedDict will remember the order of insertion). If
291-
``object_hook`` is also defined, the ``object_pairs_hook`` takes priority.
287+
This feature can be used to implement custom decoders. If ``object_hook``
288+
is also defined, the ``object_pairs_hook`` takes priority.
292289
293290
To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
294291
kwarg; otherwise ``JSONDecoder`` is used.
295-
296292
"""
297293
return loads(fp.read(),
298294
cls=cls, object_hook=object_hook,
@@ -313,10 +309,8 @@ def loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None,
313309
``object_pairs_hook`` is an optional function that will be called with the
314310
result of any object literal decoded with an ordered list of pairs. The
315311
return value of ``object_pairs_hook`` will be used instead of the ``dict``.
316-
This feature can be used to implement custom decoders that rely on the
317-
order that the key and value pairs are decoded (for example,
318-
collections.OrderedDict will remember the order of insertion). If
319-
``object_hook`` is also defined, the ``object_pairs_hook`` takes priority.
312+
This feature can be used to implement custom decoders. If ``object_hook``
313+
is also defined, the ``object_pairs_hook`` takes priority.
320314
321315
``parse_float``, if specified, will be called with the string
322316
of every JSON float to be decoded. By default this is equivalent to
@@ -337,7 +331,6 @@ def loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None,
337331
kwarg; otherwise ``JSONDecoder`` is used.
338332
339333
The ``encoding`` argument is ignored and deprecated.
340-
341334
"""
342335
if isinstance(s, str):
343336
if s.startswith('\ufeff'):

Lib/json/decoder.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,8 @@ def __init__(self, *, object_hook=None, parse_float=None,
292292
``object_pairs_hook``, if specified will be called with the result of
293293
every JSON object decoded with an ordered list of pairs. The return
294294
value of ``object_pairs_hook`` will be used instead of the ``dict``.
295-
This feature can be used to implement custom decoders that rely on the
296-
order that the key and value pairs are decoded (for example,
297-
collections.OrderedDict will remember the order of insertion). If
298-
``object_hook`` is also defined, the ``object_pairs_hook`` takes
295+
This feature can be used to implement custom decoders.
296+
If ``object_hook`` is also defined, the ``object_pairs_hook`` takes
299297
priority.
300298
301299
``parse_float``, if specified, will be called with the string
@@ -317,7 +315,6 @@ def __init__(self, *, object_hook=None, parse_float=None,
317315
characters will be allowed inside strings. Control characters in
318316
this context are those with character codes in the 0-31 range,
319317
including ``'\\t'`` (tab), ``'\\n'``, ``'\\r'`` and ``'\\0'``.
320-
321318
"""
322319
self.object_hook = object_hook
323320
self.parse_float = parse_float or float

0 commit comments

Comments
 (0)