Skip to content

Conversation

@jayaddison
Copy link
Contributor

Purpose

The goal of this pull request is to identify duplicate internal hyperlink targets -- the presence of these can cause documentation hyperlinks to resolve ambiguously (e.g. sometimes incorrectly) at build-time.

References

@AA-Turner AA-Turner added this to the 8.3.0 milestone Mar 1, 2025
@jayaddison
Copy link
Contributor Author

The changes in 4df6239 seem to introduce a large number of false-positive warnings; numbered footnotes, for example, are frequently a source of distraction with this in place. I'll move this pull request back into draft status until I can resolve that problem.

@jayaddison jayaddison marked this pull request as draft March 1, 2025 22:52
…tions

Re-uses some existing filtering for footnotes and other acceptable duplicates.

Some false-positives continue to occur with this change in place; for example,
internal hyperlink targets that are subsequently `include`d into other docs.
@jayaddison
Copy link
Contributor Author

Todo: extend the test coverage to add an example of document that is include'd into more than one other location; this appears to be another case where the same symptom (ambiguous resolution of anonymous hyperlinks) can occur.

Comment on lines +3 to +5
.. _ambiguous_shared_hyperlink:

This hyperlink target is declared once and is included by multiple documents.
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.

@gmilde
Copy link
Contributor

gmilde commented May 21, 2025

The term "anonymous" in the name of this PR is confusing:

The goal of this pull request is to identify duplicate internal hyperlink targets
[...]

Anonymous hyperlink targets don't use a reference name and may be internal or external. Example:

See `the web site`__ of my `favorite programming language`__.

__ https://www.python.org
__ Why I like Python_

Why I like Python
*****************
its nice

In every document, the number of anonymous references must match the number of anonymous targets.
Duplicate anonymous hyperlink targets would be a bug in the assignment of IDs to their <target> elements.

@jayaddison jayaddison changed the title rST: add warning about duplicate anonymous hyperlink targets rST: add warning about duplicate-declaration hyperlink targets May 21, 2025
@jayaddison
Copy link
Contributor Author

Thank you @gmilde - is edited version (rST: add warning about duplicate-declaration hyperlink targets) reasonably accurate?

@gmilde
Copy link
Contributor

gmilde commented May 21, 2025

I'd call it "rST: add warning about duplicate hyperlink target names".

@jayaddison jayaddison changed the title rST: add warning about duplicate-declaration hyperlink targets rST: add warning about duplicate hyperlink target names May 21, 2025
@jayaddison
Copy link
Contributor Author

Thank you; updated.

@gmilde
Copy link
Contributor

gmilde commented May 21, 2025

Regarding spurious warnings, see also my comment on the issue page.
#13383 (comment)

@jayaddison jayaddison marked this pull request as ready for review August 2, 2025 09:49
@AA-Turner AA-Turner modified the milestones: 8.3.0, 9.0.0 Nov 25, 2025
@jayaddison
Copy link
Contributor Author

@AA-Turner thanks for adding the 9.0.0 milestone - I worry about the potential for this to cause build breakage for potentially lots of downstream Sphinx projects, but I would also like for it to be included in an upcoming release.

Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

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

Can we use an INFO level notice for now, and add a note to upgrade it to WARNING in eg Sphinx 11?

A

@jayaddison
Copy link
Contributor Author

Seems reasonable, yep. Perhaps I'll mention it on the release thread too for inclusion, just in case anyone feels like testing it (or at least being aware of it) in advance.

@jayaddison jayaddison mentioned this pull request Nov 29, 2025

ENV_WARNINGS = """\
{root}/autodoc_fodder.py:docstring of autodoc_fodder.MarkupError:\\d+: \
DUPLICATE_LABEL_WARNINGS = False
Copy link
Member

Choose a reason for hiding this comment

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

@jayaddison perhaps just remove this? We can add it if/when the message is upgraded to a warning.

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 debatable, I admit - but I opted to prefer projecting the test coverage unchanged into the future, since the output seems reasonably unlikely to differ, and the rework involved could be an annoyance for someone (likely myself). It'd also provide a little more reassurance to someone inspecting a diff (again, sometimes myself in other contexts) that the author did in fact at least add test coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As a first preference instead of removing it entirely, I think I'd prefer to figure out whether there's a more maintainer-friendly way to express it (e.g. some mild misuse of deprecation patterns, or similar).

Copy link
Member

Choose a reason for hiding this comment

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

@jayaddison happy for you to have a look, but otherwise I'd prefer to remove it as dead code.

A

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My previous comments were word salad; I think what I should have explained up-front is: I do want this to become a warning, and I am fairly adamant about that.

So I would like to write the tests in a way that prepares for warning-level messages, while permitting info-level until then.

Copy link
Member

Choose a reason for hiding this comment

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

I'm still on the fence about making this a warning. I opened #14187 as an idea that would give me more certainty, but that's a large project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My one and only Linux kernel patch (so far, at least) disambiguated two duplicate labels, and that allowed the documentation to build reproducibly. If at all possible, I'd prefer for that not to regress (I don't anticipate that that exact label would be re-duplicated, but the same category of label-duplication problem could easily occur again elsewhere in the documentation).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I do also agree with providing advance notice and a gradual rollout though, given uncertainty about the scale of the problem)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I lie - my patch was one of a few fixes that has improved the reproducibility of the Linux kernel docs, but there is at least one other remaining nondeterminism issue in Sphinx that is relevant there.

@AA-Turner AA-Turner added the awaiting:response Waiting for a response from the author of this issue label Nov 30, 2025
@jayaddison jayaddison changed the title rST: add warning about duplicate hyperlink target names rST: add notice about duplicate hyperlink target names Nov 30, 2025
Comment on lines 22 to 27
if version_info >= (11, 0, 0):
# this code can be removed when we prepare Sphinx 11 for release
msg = 'From Sphinx 11, duplicate labels should always warn by default'
raise RemovedInSphinx11Warning(msg)
else:
DUPLICATE_LABEL_WARNINGS = version_info >= (10, 0, 0)
Copy link
Member

Choose a reason for hiding this comment

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

This isn't the right approach: we shouldn't raise warnings as exceptions, nor does it make sense to raise a module-level warning in a test file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't make sense, but it would only occur when we begin developing Sphinx 11 -- the major release after the info-level messages are upgraded to warnings. At that point, the test condition could be removed.

What's a better way to annotate test code that can be cleaned up after a certain version?

Copy link
Member

Choose a reason for hiding this comment

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

What's a better way to annotate test code that can be cleaned up after a certain version?

# xref RemovedInSphinxXXWarning

Whoever does the removals needs to search for the relevant name, so we often put things in comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, perfect. I'll adjust the test code to follow that pattern. Thank you!

@AA-Turner AA-Turner modified the milestones: 9.0.0, 9.x Nov 30, 2025
@AA-Turner
Copy link
Member

I'm going to delay this to 9.1.

A

@jayaddison
Copy link
Contributor Author

@AA-Turner this is probably too late for the 9.1.0 boat (I notice the rc1 ship has sailed), but should be ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting:response Waiting for a response from the author of this issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible bug: duplicate rST hyperlink targets don't appear to emit a warning during project processing?

3 participants