mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
gh-100272: Fix JSON serialization of OrderedDict (GH-100273)
It now preserves the order of keys.
This commit is contained in:
parent
2b38a9aa74
commit
0fe61d0838
3 changed files with 15 additions and 4 deletions
|
@ -1570,10 +1570,9 @@ encoder_listencode_dict(PyEncoderObject *s, _PyUnicodeWriter *writer,
|
|||
*/
|
||||
}
|
||||
|
||||
if (s->sort_keys) {
|
||||
|
||||
items = PyDict_Items(dct);
|
||||
if (items == NULL || PyList_Sort(items) < 0)
|
||||
if (s->sort_keys || !PyDict_CheckExact(dct)) {
|
||||
items = PyMapping_Items(dct);
|
||||
if (items == NULL || (s->sort_keys && PyList_Sort(items) < 0))
|
||||
goto bail;
|
||||
|
||||
for (Py_ssize_t i = 0; i < PyList_GET_SIZE(items); i++) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue