Fix JSON docs about loads() accepting only str objects, not bytes.

This commit is contained in:
Antoine Pitrou 2011-01-21 21:37:32 +00:00
parent 2e042d3dc2
commit 00d650baaa
2 changed files with 8 additions and 11 deletions

View file

@ -118,9 +118,8 @@ Basic Usage
file-like object). file-like object).
If *skipkeys* is ``True`` (default: ``False``), then dict keys that are not If *skipkeys* is ``True`` (default: ``False``), then dict keys that are not
of a basic type (:class:`bytes`, :class:`str`, :class:`int`, of a basic type (:class:`str`, :class:`int`, :class:`float`, :class:`bool`,
:class:`float`, :class:`bool`, ``None``) will be skipped instead of raising a ``None``) will be skipped instead of raising a :exc:`TypeError`.
:exc:`TypeError`.
The :mod:`json` module always produces :class:`str` objects, not The :mod:`json` module always produces :class:`str` objects, not
:class:`bytes` objects. Therefore, ``fp.write()`` must support :class:`str` :class:`bytes` objects. Therefore, ``fp.write()`` must support :class:`str`
@ -203,15 +202,11 @@ Basic Usage
.. function:: loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw) .. function:: loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
Deserialize *s* (a :class:`bytes` or :class:`str` instance containing a JSON Deserialize *s* (a :class:`str` instance containing a JSON document) to a
document) to a Python object. Python object.
If *s* is a :class:`bytes` instance and is encoded with an ASCII based encoding The other arguments have the same meaning as in :func:`load`, except
other than UTF-8 (e.g. latin-1), then an appropriate *encoding* name must be *encoding* which is ignored and deprecated.
specified. Encodings that are not ASCII based (such as UCS-2) are not
allowed and should be decoded to :class:`str` first.
The other arguments have the same meaning as in :func:`load`.
Encoders and decoders Encoders and decoders

View file

@ -298,6 +298,8 @@ def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
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.
The ``encoding`` argument is ignored and deprecated.
""" """
if (cls is None and object_hook is None and if (cls is None and object_hook is None and
parse_int is None and parse_float is None and parse_int is None and parse_float is None and