SF.net SVN: docutils:[10305 ] trunk/docutils

milde--- via Docutils-checkins <[email protected]> Fri, 27 Mar 2026 21:45:53 +0000
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 10305
          http://sourceforge.net/p/docutils/code/10305
Author:   milde
Date:     2026-03-27 21:45:52 +0000 (Fri, 27 Mar 2026)
Log Message:
-----------
Drop spurious back references from system messages.

Fix the conditional deciding whether to add a "backrefs" attribute to
a system message.
The test for empty `<target>`s (which are not shown in the output document)
now also catches indirect targets with a "refid" but no children.

Modified Paths:
--------------
    trunk/docutils/docutils/nodes.py
    trunk/docutils/test/test_parsers/test_rst/test_inline_markup.py
    trunk/docutils/test/test_parsers/test_rst/test_targets.py
    trunk/docutils/test/test_transforms/test_hyperlinks.py

Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py	2026-03-27 08:41:24 UTC (rev 10304)
+++ trunk/docutils/docutils/nodes.py	2026-03-27 21:45:52 UTC (rev 10305)
@@ -2144,7 +2144,7 @@
                 self.set_id(old_node)  # set id to get running numbers right
         if level:
             # don't add backref id for empty targets (not shown in output)
-            if isinstance(node, target) and 'refuri' in node:
+            if isinstance(node, target) and not node.children:
                 backrefs = []
             else:
                 backrefs = [self.set_id(node)]

Modified: trunk/docutils/test/test_parsers/test_rst/test_inline_markup.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_inline_markup.py	2026-03-27 08:41:24 UTC (rev 10304)
+++ trunk/docutils/test/test_parsers/test_rst/test_inline_markup.py	2026-03-27 21:45:52 UTC (rev 10305)
@@ -1300,7 +1300,7 @@
         <target ids="tg2" names="tg2">
             tg2
         .
-    <system_message backrefs="link-1" level="1" line="6" source="test data" type="INFO">
+    <system_message level="1" line="6" source="test data" type="INFO">
         <paragraph>
             Duplicate implicit target name: "link".
     <paragraph>

Modified: trunk/docutils/test/test_parsers/test_rst/test_targets.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_targets.py	2026-03-27 08:41:24 UTC (rev 10304)
+++ trunk/docutils/test/test_parsers/test_rst/test_targets.py	2026-03-27 21:45:52 UTC (rev 10305)
@@ -265,7 +265,7 @@
             targets
          (same refname):
     <target ids="link" names="link" refname="targets">
-    <system_message backrefs="link-1" level="1" line="5" source="test data" type="INFO">
+    <system_message level="1" line="5" source="test data" type="INFO">
         <paragraph>
             Duplicate name "link" for external target "targets".
     <target dupnames="link" ids="link-1" refname="targets">
@@ -323,7 +323,7 @@
     <section dupnames="title" ids="title">
         <title>
             Title
-        <system_message backrefs="title-1" level="1" line="6" source="test data" type="INFO">
+        <system_message level="1" line="6" source="test data" type="INFO">
             <paragraph>
                 Target name overrides implicit target name "title".
         <target ids="title-1" names="title">
@@ -375,13 +375,13 @@
     <target dupnames="title" ids="title">
     <paragraph>
         First.
-    <system_message backrefs="title-1" level="2" line="7" source="test data" type="WARNING">
+    <system_message level="2" line="7" source="test data" type="WARNING">
         <paragraph>
             Duplicate explicit target name: "title".
     <target dupnames="title" ids="title-1">
     <paragraph>
         Second.
-    <system_message backrefs="title-2" level="2" line="11" source="test data" type="WARNING">
+    <system_message level="2" line="11" source="test data" type="WARNING">
         <paragraph>
             Duplicate explicit target name: "title".
     <target dupnames="title" ids="title-2">
@@ -464,7 +464,7 @@
                     Duplicate explicit target name: "target".
             <paragraph>
                 Autonumber-labeled footnote target.
-        <system_message backrefs="target-3" level="2" line="12" source="test data" type="WARNING">
+        <system_message level="2" line="12" source="test data" type="WARNING">
             <paragraph>
                 Duplicate explicit target name: "target".
         <target dupnames="target" ids="target-3">

Modified: trunk/docutils/test/test_transforms/test_hyperlinks.py
===================================================================
--- trunk/docutils/test/test_transforms/test_hyperlinks.py	2026-03-27 08:41:24 UTC (rev 10304)
+++ trunk/docutils/test/test_transforms/test_hyperlinks.py	2026-03-27 21:45:52 UTC (rev 10305)
@@ -292,7 +292,7 @@
     <target dupnames="ztarget" refid="ztarget">
     <paragraph ids="ztarget">
         First
-    <system_message backrefs="ztarget-1" level="2" line="5" source="test data" type="WARNING">
+    <system_message level="2" line="5" source="test data" type="WARNING">
         <paragraph>
             Duplicate explicit target name: "ztarget".
     <target dupnames="ztarget" refid="ztarget-1">

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.