From: Günter M. <mi...@us...> - 2022-05-25 19:37:43
|
> This captures the bug behind `branches/index-bug`. I'm not sure the > general case of `index` is worth fixing, as `Text` nodes are a special > case, but it might have implications for `Node.findall`. I am not sure whether it is an error with `nodes.Element.index()`. [r5594] moves the proposed fix into a place in `node.traverse()` that is now part of `node.findall()`. `nodes.Text` inherits from `Node` and `str`. From `str` it inherits: `nodes.Text("tx") == nodes.Text("tx")`. Maybe it should rather compare like `Element` instances `nodes.Element('', nodes.Text('tx')) != nodes.Element('', nodes.Text('tx'))` But this may break use cases. :( Element.index() behaves like list.index(): ta2 = 'ta' ['ta', 'tü', ta2, 'ta'].index(ta2) == 2 There is no documentation saying it should behave differently. Node.findall() uses Element.index() to determine the index of a node in its parents list of children (i.e. relative to its siblings). This fails, e.g., for the second "hallo" in a paragraph like "hallo *du*\ hallo *ich*". --- ** [bugs:#448] `Element.index()` returns incorrect results for `Text` nodes** **Status:** open **Created:** Tue May 24, 2022 11:38 PM UTC by Adam Turner **Last Updated:** Tue May 24, 2022 11:38 PM UTC **Owner:** nobody This captures the bug behind `branches/index-bug`. I'm not sure the general case of `index` is worth fixing, as `Text` nodes are a special case, but it might have implications for `Node.findall`. ```python >>> from docutils import nodes >>> tree = nodes.Element() >>> blah1 = nodes.Text("blah") >>> blah2 = nodes.Text("blah") >>> tree += [nodes.Text("node1"), blah1, blah2] >>> print(tree.pformat()) <Element> node1 blah blah >>> tree[tree.index(blah2)] is blah2 False >>> tree[tree.index(blah2)] is blah1 True ``` A --- Sent from sourceforge.net because doc...@li... is subscribed to https://sourceforge.net/p/docutils/bugs/ To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/docutils/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |