R. David Murray <rdmur...@bitdance.com> added the comment:

json keys *are* strings, so the fact that we support other object types as keys 
and coerce them to strings is an "extra feature" of python, and is actually a 
somewhat questionable feature.  The reproducible use case is solved by the fact 
that dicts are now ordered, with no extra work on the part of the programmer.  
Likewise, if you want custom sorting you can ensure your dict is ordered the 
way you want it to be, as you indicate.  The remaining use case for sort_keys, 
then (and one for which it is *commonly* used) is sorting the keys 
lexicographically, and for that, sorting the coereced strings is correct per 
the json standard (in which all keys are required to be strings).

Note that sort_keys will not be removed for backward compatibility reasons, so 
the only question is whether or not the increased functionality of coercing 
first is worth the trouble to implement.  I'm actually only +0 on it, since I 
don't consider it good practice to json-ize dicts that have non-string keys.  
The reason I'm + is because it would increase backward compatibility with 
python2 (not the ordering of the output, we can't make that work, but in the 
fact that it would no longer raise an error in python3).

We'll see if other core developers agree or disagree.

----------

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

Reply via email to