Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
629338f1
Commit
629338f1
authored
Apr 03, 2018
by
INADA Naoki
Committed by
GitHub
Apr 03, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-32360: Remove object_pairs_hook=OrderedDict examples (GH-5001)
parent
badb894b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
25 deletions
+11
-25
Doc/library/json.rst
Doc/library/json.rst
+4
-8
Lib/json/__init__.py
Lib/json/__init__.py
+5
-12
Lib/json/decoder.py
Lib/json/decoder.py
+2
-5
No files found.
Doc/library/json.rst
View file @
629338f1
...
@@ -230,10 +230,8 @@ Basic Usage
...
@@ -230,10 +230,8 @@ Basic Usage
*object_pairs_hook* is an optional function that will be called with the
*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
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
return value of *object_pairs_hook* will be used instead of the
:class:`dict`. This feature can be used to implement custom decoders that
:class:`dict`. This feature can be used to implement custom decoders.
rely on the order that the key and value pairs are decoded (for example,
If *object_hook* is also defined, the *object_pairs_hook* takes priority.
:func:`collections.OrderedDict` will remember the order of insertion). If
*object_hook* is also defined, the *object_pairs_hook* takes priority.
.. versionchanged:: 3.1
.. versionchanged:: 3.1
Added support for *object_pairs_hook*.
Added support for *object_pairs_hook*.
...
@@ -325,10 +323,8 @@ Encoders and Decoders
...
@@ -325,10 +323,8 @@ Encoders and Decoders
*object_pairs_hook*, if specified will be called with the result of every
*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
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
*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
feature can be used to implement custom decoders. If *object_hook* is also
that the key and value pairs are decoded (for example,
defined, the *object_pairs_hook* takes priority.
:func:`collections.OrderedDict` will remember the order of insertion). If
*object_hook* is also defined, the *object_pairs_hook* takes priority.
.. versionchanged:: 3.1
.. versionchanged:: 3.1
Added support for *object_pairs_hook*.
Added support for *object_pairs_hook*.
...
...
Lib/json/__init__.py
View file @
629338f1
...
@@ -28,8 +28,7 @@ Encoding basic Python object hierarchies::
...
@@ -28,8 +28,7 @@ Encoding basic Python object hierarchies::
Compact encoding::
Compact encoding::
>>> import json
>>> import json
>>> from collections import OrderedDict
>>> mydict = {'4': 5, '6': 7}
>>> mydict = OrderedDict([('4', 5), ('6', 7)])
>>> json.dumps([1,2,3,mydict], separators=(',', ':'))
>>> json.dumps([1,2,3,mydict], separators=(',', ':'))
'[1,2,3,{"4":5,"6":7}]'
'[1,2,3,{"4":5,"6":7}]'
...
@@ -285,14 +284,11 @@ def load(fp, *, cls=None, object_hook=None, parse_float=None,
...
@@ -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
``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
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``.
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
This feature can be used to implement custom decoders. If ``object_hook``
order that the key and value pairs are decoded (for example,
is also defined, the ``object_pairs_hook`` takes priority.
collections.OrderedDict will remember the order of insertion). If
``object_hook`` is also defined, the ``object_pairs_hook`` takes priority.
To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
kwarg; otherwise ``JSONDecoder`` is used.
kwarg; otherwise ``JSONDecoder`` is used.
"""
"""
return
loads
(
fp
.
read
(),
return
loads
(
fp
.
read
(),
cls
=
cls
,
object_hook
=
object_hook
,
cls
=
cls
,
object_hook
=
object_hook
,
...
@@ -313,10 +309,8 @@ def loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None,
...
@@ -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
``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
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``.
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
This feature can be used to implement custom decoders. If ``object_hook``
order that the key and value pairs are decoded (for example,
is also defined, the ``object_pairs_hook`` takes priority.
collections.OrderedDict will remember the order of insertion). If
``object_hook`` is also defined, the ``object_pairs_hook`` takes priority.
``parse_float``, if specified, will be called with the string
``parse_float``, if specified, will be called with the string
of every JSON float to be decoded. By default this is equivalent to
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,
...
@@ -337,7 +331,6 @@ def loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None,
kwarg; otherwise ``JSONDecoder`` is used.
kwarg; otherwise ``JSONDecoder`` is used.
The ``encoding`` argument is ignored and deprecated.
The ``encoding`` argument is ignored and deprecated.
"""
"""
if
isinstance
(
s
,
str
):
if
isinstance
(
s
,
str
):
if
s
.
startswith
(
'
\
ufeff
'
):
if
s
.
startswith
(
'
\
ufeff
'
):
...
...
Lib/json/decoder.py
View file @
629338f1
...
@@ -292,10 +292,8 @@ class JSONDecoder(object):
...
@@ -292,10 +292,8 @@ class JSONDecoder(object):
``object_pairs_hook``, if specified will be called with the result of
``object_pairs_hook``, if specified will be called with the result of
every JSON object decoded with an ordered list of pairs. The return
every JSON object decoded with an ordered list of pairs. The return
value of ``object_pairs_hook`` will be used instead of the ``dict``.
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
This feature can be used to implement custom decoders.
order that the key and value pairs are decoded (for example,
If ``object_hook`` is also defined, the ``object_pairs_hook`` takes
collections.OrderedDict will remember the order of insertion). If
``object_hook`` is also defined, the ``object_pairs_hook`` takes
priority.
priority.
``parse_float``, if specified, will be called with the string
``parse_float``, if specified, will be called with the string
...
@@ -317,7 +315,6 @@ class JSONDecoder(object):
...
@@ -317,7 +315,6 @@ class JSONDecoder(object):
characters will be allowed inside strings. Control characters in
characters will be allowed inside strings. Control characters in
this context are those with character codes in the 0-31 range,
this context are those with character codes in the 0-31 range,
including ``'
\
\
t'`` (tab), ``'
\
\
n'``, ``'
\
\
r'`` and ``'
\
\
0'``.
including ``'
\
\
t'`` (tab), ``'
\
\
n'``, ``'
\
\
r'`` and ``'
\
\
0'``.
"""
"""
self
.
object_hook
=
object_hook
self
.
object_hook
=
object_hook
self
.
parse_float
=
parse_float
or
float
self
.
parse_float
=
parse_float
or
float
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment