Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4df6239
rST: add warning about duplicate anonymous hyperlink targets
jayaddison Mar 1, 2025
2dcdbce
Add CHANGES.rst entry
jayaddison Mar 1, 2025
7f561ff
rST: reduce false-positive warnings about duplicate hyperlink declara…
jayaddison Mar 2, 2025
e98d5b4
Merge branch 'master' into warn-about-duplicate-anonymous-hyperlinks
jayaddison Mar 24, 2025
f95f62e
Tests: add an anonymous hyperlink included from multiple documents
jayaddison Mar 24, 2025
0a93fa4
Merge branch 'master' into issue-13383/duplicate-internal-hyperlink-t…
jayaddison May 7, 2025
5f9b703
Merge branch 'master' into issue-13383/duplicate-internal-hyperlink-t…
jayaddison Jun 2, 2025
5edb56d
tests: build-warnings: fix shared-hyperlink warning match expectations
jayaddison Jun 2, 2025
f54dc08
tests: build-warnings: adjust expected exception-raiser warning message
jayaddison Jun 2, 2025
f78dff0
Merge branch 'master' into issue-13383/duplicate-internal-hyperlink-t…
jayaddison Oct 15, 2025
4f3bf7f
Merge branch 'master' into issue-13383/duplicate-internal-hyperlink-t…
jayaddison Nov 9, 2025
07b5ed7
rST: remove duplicate anonymous label from `warn` to `info` severity
jayaddison Nov 29, 2025
ea23ca8
Merge branch 'master' into issue-13383/duplicate-internal-hyperlink-t…
jayaddison Nov 29, 2025
69b53bc
Apply `ruff format`
jayaddison Nov 29, 2025
a3335e9
Adapt test case to anticipated feature rollout schedule
jayaddison Nov 30, 2025
accc8cf
Merge branch 'master' into issue-13383/duplicate-internal-hyperlink-t…
jayaddison Dec 16, 2025
316124a
Tests: apply a more sensible deprecation strategy to duplicate-label …
jayaddison Dec 16, 2025
74f0e01
Tests: typo/syntax fixups in comment
jayaddison Dec 16, 2025
cdbf375
Tests: retain `unindent_warning` test coverage
jayaddison Dec 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ Features added
Bugs fixed
----------

* #13383: Emit a warning for duplicate internal hyperlink declarations.
Patch by James Addison.

Testing
-------
7 changes: 7 additions & 0 deletions sphinx/domains/std/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,13 @@ def process_doc(
env.doc2path(self.labels[name][0]),
location=node,
)
elif name in self.anonlabels:
logger.warning(
__('duplicate label %s, other instance in %s'),
name,
env.doc2path(self.anonlabels[name][0]),
location=node,
)
self.anonlabels[name] = docname, labelid
if node.tagname == 'section':
title = cast('nodes.title', node[0])
Expand Down
9 changes: 9 additions & 0 deletions tests/roots/test-warnings/hyperlinks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:orphan:

.. _ambiguous_hyperlink:

This hyperlink target is declared with the same name in two files.

.. include:: includes/shared-hyperlinks.rst

This is one of two places where the shared-hyperlinks file is included.
5 changes: 5 additions & 0 deletions tests/roots/test-warnings/includes/shared-hyperlinks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:orphan:

.. _ambiguous_shared_hyperlink:

This hyperlink target is declared once and is included by multiple documents.
Comment on lines +3 to +5
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AA-Turner @picnixz is there a way to determine a unique declaration identifier/path -- e.g. where a hyperlink was defined, instead of where it is used?

When reporting warnings about duplicated anonymous hyperlinks, it'd be nice to be able to indicate clearly that the duplication originates from multiple includes of a common document, instead of weird/confusing warnings about the hyperlinks appearing in multiple documents.

8 changes: 8 additions & 0 deletions tests/roots/test-warnings/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ This used to crash: :option:`&option`
.. missing citation

[missing]_ citation

.. _ambiguous_hyperlink:

This hyperlink target is declared with the same name in two files.

.. include:: includes/shared-hyperlinks.rst

This is one of two places where the shared-hyperlinks file is included.
1 change: 1 addition & 0 deletions tests/test_builders/test_build_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
{root}/index.rst:\\d+: WARNING: Encoding 'utf-8-sig' used for reading included \
file '{root}/wrongenc.inc' seems to be wrong, try giving an :encoding: option \\[docutils\\]
{root}/index.rst:\\d+: WARNING: invalid single index entry '' \\[index\\]
{root}/index.rst:\\d+: WARNING: duplicate label ambiguous_hyperlink, other instance in {root}/hyperlinks.rst
{root}/index.rst:\\d+: WARNING: image file not readable: foo.png \\[image.not_readable\\]
{root}/index.rst:\\d+: WARNING: download file not readable: {root}/nonexisting.png \\[download.not_readable\\]
{root}/undecodable.rst:\\d+: WARNING: undecodable source characters, replacing \
Expand Down
Loading