[issue23493] optimize sort_keys in json module by using operator.itemgetter()

Mickaël Schoentgen report at bugs.python.org
Thu Sep 2 11:43:59 EDT 2021


Mickaël Schoentgen <contact at tiger-222.fr> added the comment:

I am wondering why the change was not backported to 3.6 and 3.7?
It introduces different behavior.

For instance, I need to keep duplicate keys from JSON data (because it is allowed by the RFC and it is a missing feature for tools such like HTTPie).

Have a look at repro-sorting.py.

On Python 3.6 and 3.7, the output is not sorted:

    {
        "dps": {
            "1630064726": 5.0,
            "1630064726": 3.0,
            "1630064726": 6.0
        }
    }

Starting with Python 3.8, the output is sorted as expected:

    {
        "dps": {
            "1630064726": 3.0,
            "1630064726": 5.0,
            "1630064726": 6.0
        }
    }

I could open pull requests for both 3.6 and 3.7 branches, if you think it is worth and allowed by the current maintenance status.

----------
nosy: +Tiger-222
Added file: https://bugs.python.org/file50256/repro-sorting.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue23493>
_______________________________________


More information about the Python-bugs-list mailing list