Gregory P. Smith added the comment:

upstream simplejson (of which json is an earlier snapshot of) has an encoding 
parameter on its dump and dumps method.  Lets NOT break compatibility with that 
API.

Our users use these modules interchangeably today, upgrading from stdlib json 
to simplejson when they need more features or speed without having to change 
their code.

simplejson's dumps(encoding=) parameter tells the module what encoding to 
decode bytes objects found within the data structure as (whereas Python 3.3's 
builtin json module being older doesn't even support that use case and raises a 
TypeError when bytes are encountered within the structure being serialized).

http://simplejson.readthedocs.org/en/latest/

A json.dump_bytes() function implemented as:

def dump_bytes(*args, **kwargs):
  return dumps(*args, **kwargs).encode('utf-8')

makes some sense.. but it is really trivial for anyone to write that 
.encode(...) themselves.

a dump_bytes_to_file method that acts like dump() and calls .encode('utf-8') on 
all str's before passing them to the write call is also doable... but it seems 
easier to just let people use an existing io wrapper to do that for them as 
they already are.

As for load/loads, it is easy to allow that to accept bytes as input and assume 
it comes utf-8 encoded.  simplejson already does this.  json does not.

----------
nosy: +gregory.p.smith

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue19837>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to