[Docutils-develop] [docutils:bugs] #448 `Element.index()` returns
incorrect results for `Text` nodes
From: Adam T. <aa-...@us...> - 2022-05-24 23:38:06
|
--- ** [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. |
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. |
From: Günter M. <mi...@us...> - 2022-05-25 19:50:53
|
addendum: in xml.dom, Text nodes compare by instance. --- ** [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. |
[Docutils-develop] [docutils:bugs] #448 `Element.index()` returns
incorrect results for `Text` nodes
From: Günter M. <mi...@us...> - 2022-05-31 11:36:35
|
The attached patch combines an update of the fix in the "index-bug" branch [r5594] with a minimal test case. Attachments: - [0001-Fix-nodes-Node-findall-for-Text-nodes.patch](https://sourceforge.net/p/docutils/bugs/_discuss/thread/11ae66ddc2/72e4/attachment/0001-Fix-nodes-Node-findall-for-Text-nodes.patch) (4.3 kB; text/x-patch) --- ** [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. |
[Docutils-develop] [docutils:bugs] #448 `Element.index()` returns
incorrect results for `Text` nodes
From: Günter M. <mi...@us...> - 2022-06-10 11:12:14
|
- **status**: open --> open-fixed - **Comment**: Fixed in [r9067]. Thank you for report and contributions. --- ** [bugs:#448] `Element.index()` returns incorrect results for `Text` nodes** **Status:** open-fixed **Created:** Tue May 24, 2022 11:38 PM UTC by Adam Turner **Last Updated:** Tue May 31, 2022 11:36 AM 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. |
[Docutils-develop] [docutils:bugs] #448 `Element.index()` returns
incorrect results for `Text` nodes
From: Günter M. <mi...@us...> - 2022-07-06 06:34:14
|
- **status**: open-fixed --> closed-fixed - **Comment**: Fixed in Docutils 0.19. Thank you for reporting. --- ** [bugs:#448] `Element.index()` returns incorrect results for `Text` nodes** **Status:** closed-fixed **Created:** Tue May 24, 2022 11:38 PM UTC by Adam Turner **Last Updated:** Fri Jun 10, 2022 11:12 AM 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. |