Skip to content

[3.7] bpo-32360: Remove object_pairs_hook=OrderedDict examples (GH-5001) #6361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 4 additions & 8 deletions Doc/library/json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,8 @@ Basic Usage
*object_pairs_hook* is an optional function that will be called with the
result of any object literal decoded with an ordered list of pairs. The
return value of *object_pairs_hook* will be used instead of the
:class:`dict`. This feature can be used to implement custom decoders that
rely on the order that the key and value pairs are decoded (for example,
:func:`collections.OrderedDict` will remember the order of insertion). If
*object_hook* is also defined, the *object_pairs_hook* takes priority.
:class:`dict`. This feature can be used to implement custom decoders.
If *object_hook* is also defined, the *object_pairs_hook* takes priority.

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

.. versionchanged:: 3.1
Added support for *object_pairs_hook*.
Expand Down
17 changes: 5 additions & 12 deletions Lib/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
Compact encoding::

>>> import json
>>> from collections import OrderedDict
>>> mydict = OrderedDict([('4', 5), ('6', 7)])
>>> mydict = {'4': 5, '6': 7}
>>> json.dumps([1,2,3,mydict], separators=(',', ':'))
'[1,2,3,{"4":5,"6":7}]'

Expand Down Expand Up @@ -285,14 +284,11 @@ def load(fp, *, cls=None, object_hook=None, parse_float=None,
``object_pairs_hook`` is an optional function that will be called with the
result of any object literal decoded with an ordered list of pairs. The
return value of ``object_pairs_hook`` will be used instead of the ``dict``.
This feature can be used to implement custom decoders that rely on the
order that the key and value pairs are decoded (for example,
collections.OrderedDict will remember the order of insertion). If
``object_hook`` is also defined, the ``object_pairs_hook`` takes priority.
This feature can be used to implement custom decoders. If ``object_hook``
is also defined, the ``object_pairs_hook`` takes priority.

To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
kwarg; otherwise ``JSONDecoder`` is used.

"""
return loads(fp.read(),
cls=cls, object_hook=object_hook,
Expand All @@ -313,10 +309,8 @@ def loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None,
``object_pairs_hook`` is an optional function that will be called with the
result of any object literal decoded with an ordered list of pairs. The
return value of ``object_pairs_hook`` will be used instead of the ``dict``.
This feature can be used to implement custom decoders that rely on the
order that the key and value pairs are decoded (for example,
collections.OrderedDict will remember the order of insertion). If
``object_hook`` is also defined, the ``object_pairs_hook`` takes priority.
This feature can be used to implement custom decoders. If ``object_hook``
is also defined, the ``object_pairs_hook`` takes priority.

``parse_float``, if specified, will be called with the string
of every JSON float to be decoded. By default this is equivalent to
Expand All @@ -337,7 +331,6 @@ def loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None,
kwarg; otherwise ``JSONDecoder`` is used.

The ``encoding`` argument is ignored and deprecated.

"""
if isinstance(s, str):
if s.startswith('\ufeff'):
Expand Down
7 changes: 2 additions & 5 deletions Lib/json/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,8 @@ def __init__(self, *, object_hook=None, parse_float=None,
``object_pairs_hook``, if specified will be called with the result of
every JSON object decoded with an ordered list of pairs. The return
value of ``object_pairs_hook`` will be used instead of the ``dict``.
This feature can be used to implement custom decoders that rely on the
order that the key and value pairs are decoded (for example,
collections.OrderedDict will remember the order of insertion). If
``object_hook`` is also defined, the ``object_pairs_hook`` takes
This feature can be used to implement custom decoders.
If ``object_hook`` is also defined, the ``object_pairs_hook`` takes
priority.

``parse_float``, if specified, will be called with the string
Expand All @@ -317,7 +315,6 @@ def __init__(self, *, object_hook=None, parse_float=None,
characters will be allowed inside strings. Control characters in
this context are those with character codes in the 0-31 range,
including ``'\\t'`` (tab), ``'\\n'``, ``'\\r'`` and ``'\\0'``.

"""
self.object_hook = object_hook
self.parse_float = parse_float or float
Expand Down