This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Clay Gerrard
Recipients Clay Gerrard, barry, chrism, cvrebert, eric.araujo, ezio.melotti, gregory.p.smith, jleedev, kdwyer, martin.panter, ncoghlan, pitrou, serhiy.storchaka, socketpair, terry.reedy, vstinner
Date 2017-03-08.05:59:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1488952768.76.0.595891370814.issue19837@psf.upfronthosting.co.za>
In-reply-to
Content
and for *encoding* case?  Can you just add the encoding argument back to json.dumps?  Have it default to None because of backwards compatibility in python3 and continue to return strings by default... 

... and then *everyone* that ever wants to *serialize* an object to json because they want to put it on a wire or w/e will hopefully someday learn when you call json.dumps you *always* set encoding='utf-8' and it will always return utf-8 encoded bytes (which is the same thing it would have done py2 regardless)?

Is it confusing for the py3 encoding argument to mean something different than py2?  Probably?  The encoding argument in py2 was there to tell the Encoder how to decode keys and values who's strings were acctually utf-8 encoded bytes.  But w/e py3 doesn't have that problem - so py3 can unambiguously hijack dumps' encoding param to mean bytes!  Then, sure, maybe the fact I can write:

    sock.send(json.dumps(obj, encoding='utf-8'))

... in either language is just a happy coincidence - but it'd be useful nevertheless.

Or I could be wrong.  I've not been thinking about this for 3 years.  But I have bumped into this a couple of times in the years since starting to dream of python 3.2^H4^H5^H6^H7 support - but until then I do seem to frequently forget json.dumps(obj).decode('utf-8') so maybe my suggestion isn't really any better!?
History
Date User Action Args
2017-03-08 05:59:28Clay Gerrardsetrecipients: + Clay Gerrard, barry, terry.reedy, gregory.p.smith, chrism, ncoghlan, pitrou, vstinner, kdwyer, ezio.melotti, eric.araujo, cvrebert, socketpair, martin.panter, serhiy.storchaka, jleedev
2017-03-08 05:59:28Clay Gerrardsetmessageid: <1488952768.76.0.595891370814.issue19837@psf.upfronthosting.co.za>
2017-03-08 05:59:28Clay Gerrardlinkissue19837 messages
2017-03-08 05:59:27Clay Gerrardcreate