[New-bugs-announce] [issue37792] xml.etree.ElementTree.Element.__eq__ does compare only objects identity
Marco Sulla
report at bugs.python.org
Thu Aug 8 05:57:04 EDT 2019
New submission from Marco Sulla <launchpad.net at marco.sulla.e4ward.com>:
Currectly, even if two `Element`s elem1 and elem2 are different objects but the tree is identical, elem1 == elem2 returns False. The only effective way to compare two `Element`s is
ElementTree.tostring(elem1) == ElementTree.tostring(elem2)
Furthermore, from 3.8 this could be not true anymore, since the order of insertion of attributes will be preserved. So if I simply wrote a tag with two identical attributes, but with different order, the trick will not work anymore.
Is it so much complicated to implement an __eq__ for `Element` that traverse its tree?
PS: some random remarks about xml.etree.ElementTree module:
1. why `fromstring` and `fromstringlist` separated functions? `fromstring` could use duck typing for the main argument, and `fromstringlist` deprecated.
2. `SubElement`: why the initial is a capital letter? It seems the constructor of a different class, while it's a factory function. I'll change it to `subElement` and deprecate `SubElement`
----------
components: Library (Lib)
messages: 349230
nosy: Marco Sulla
priority: normal
severity: normal
status: open
title: xml.etree.ElementTree.Element.__eq__ does compare only objects identity
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37792>
_______________________________________
More information about the New-bugs-announce
mailing list