#19307: Improve error message for json.load(s) while passing objects of the wrong type.

This commit is contained in:
Ezio Melotti 2013-10-21 01:52:33 +03:00
parent 4ea16e56eb
commit a0e768ccc2
3 changed files with 14 additions and 1 deletions

View file

@ -310,6 +310,9 @@ def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
The ``encoding`` argument is ignored and deprecated.
"""
if not isinstance(s, str):
raise TypeError('the JSON object must be str, not {!r}'.format(
s.__class__.__name__))
if (cls is None and object_hook is None and
parse_int is None and parse_float is None and
parse_constant is None and object_pairs_hook is None and not kw):