Nick Coghlan added the comment:
I'm currently migrating a project that predates requests, and ended up needing
to replace several "json.loads" calls with a "_load_json" helper that is just
an alias for json.loads in Python 2, and defined as this in Python 3:
def _load_json(data):
return json.loads(data.decode())
To get that case to "just work", all I would have needed is for json.loads to
accept bytes input, and assume it is UTF-8 encoded, that same way simplejson
does. Since there aren't any type ambiguities associated with that, I think it
would make sense for us to go ahead and implement at least that much for Python
3.6.
By contrast, if I'd been doing *encoding*, I don't think there's anything the
Python 3 standard library could have changed *on its own* to make things just
work - I would have needed to change my code somehow.
However, a new "dump_bytes" API could still be beneficial on that front as long
as it was also added to simplejson: code that needed to run in the common
Python 2/3 subset could use "simplejson.dump_bytes", while 3.6+ only code could
just use the standard library version.
Having dump_bytes() next to dumps() in the documentation would also provide a
better hook for explaining the difference between JSON-as-text-encoding (with
"str" output) and JSON-as-wire-encoding (with "bytes" output after encoding the
str representation as UTF-8).
In both cases, I think it would make sense to leave the non-UTF-8 support to
simplejson and have the stdlib version be UTF-8 only.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue19837>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com