[issue22767] `separators` argument to json.dumps() behaves unexpectedly across 2.x vs 3.x

R. David Murray report at bugs.python.org
Thu Oct 30 21:00:07 CET 2014


R. David Murray added the comment:

Or, to put it another way, we agree with you that both cases should behave the same: using binary data in a json dumps call should raise an error.  And in python3 they do.  But in python2 there is a confusion as to what is text and what is binary, and so sometimes things work that shouldn't.  In python2 a binary string with non-ascii characters is accepted by the dumps call...it shouldn't be since json is defined as a text protocol.  But it is baked into the python2 string model that it such binary does work, because in python2 it was assumed that the programmer was responsible for making sure that the encoding of all their binary strings was consistent.   But to mix unicode and binary, you *must* make the encoding of the binary strings explicit, otherwise there's no way to correctly compose the binary data with the text data.
So, as soon as (but only as soon as) you mix unicode with your non-ascii data, your program blows up.

Thus python3.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22767>
_______________________________________


More information about the Python-bugs-list mailing list