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 vstinner
Recipients Mariatta, dfrojas, eli.bendersky, lukasz.langa, matrixise, nedbat, rhettinger, scoder, serhiy.storchaka, sivert, taleinat, vstinner
Date 2019-03-18.16:10:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1552925403.22.0.204093221923.issue34160@roundup.psfhosted.org>
In-reply-to
Content
Please don't break the backward compatibility without an easy way to retrieve Python 3.7 behavior.

I set the priority to release blocker until a consensus can be found, and I add Lukasz (Python 3.8 release manager) in the loop.


Ned Batchelder: "I'm a bit mystified why people are still opposed to providing sorting control, even after people are resorting to "hack work-arounds."  The (two) pull requests that provide the control are simple, easy to understand, and easy to test."

I concur. I'm fine with sorting by default, but it breaks the backward compatibility on purpose without providing an option to opt-in for the old behavior :-(

Many XML parsers rely on the order of attributes. It's part of the XML "semantics". Well, it shouldn't, but I cannot fix all applications around the world to explain them that Python is right, and they are all wrong :-)

It's not straighforward to fix an application to get Python 3.7 behavior. I would prefer to not have to copy-paste Stefan Behnel's recipe in every project using XML who wants to sort attributes:

"""
Something like this:

def sort_attributes(root):
    for el in root.iter():
        attrib = el.attrib
        if len(attrib) > 1:
            attribs = sorted(attrib.items())
            attrib.clear()
            attrib.update(attribs)
"""

This recipe does modify the document and so changes the behavior of the application when it iterates on attributes later, whereas in Python 3.7 attributes are only sorted while writing the XML into a file.
History
Date User Action Args
2019-03-18 16:10:03vstinnersetrecipients: + vstinner, rhettinger, scoder, taleinat, nedbat, eli.bendersky, lukasz.langa, serhiy.storchaka, matrixise, sivert, Mariatta, dfrojas
2019-03-18 16:10:03vstinnersetmessageid: <1552925403.22.0.204093221923.issue34160@roundup.psfhosted.org>
2019-03-18 16:10:03vstinnerlinkissue34160 messages
2019-03-18 16:10:03vstinnercreate