Skip to content

Conversation

@mattwang44
Copy link
Contributor

Purpose

Reduce false positive i18n.inconsistent_references warnings for pending_xref nodes.

For pending_xref, compare by reftarget only (not full rawsource) and ignore order. This allows translators to:

  • Reorder references for natural sentence flow
  • Translate display text

Other reference types retain the original behavior.

References

…g_xref

Add two parameters to `_NodeUpdater.compare_references()` method to support flexible reference comparison in translations:

- `key_func`: Extract comparison key from references (default: rawsource)
- `ignore_order`: Sort keys before comparing to allow reordering
@AA-Turner AA-Turner added this to the 9.0.x milestone Dec 1, 2025
@AA-Turner AA-Turner changed the title fix(i18n): Allow reordered refs and translated display text in pending_xref Allow reordered refs and translated display text in pending_xref Dec 2, 2025
@AA-Turner
Copy link
Member

@mattwang44 can you add a CHANGES entry?

Comment on lines +371 to +374
# Compare by reftarget only, allowing translated display text.
# Ignore order since translators may legitimately reorder references.
key_func=lambda ref: ref.get('reftarget'),
ignore_order=True,
Copy link
Member

Choose a reason for hiding this comment

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

Should any of the other compare_references() calls have ignore_order=True?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I'm not pretty sure.
I only applied it to update_pending_xrefs() since this would slash all those building warnings regarding sequence issue from the pydoc-zh-tw project, but I believe making it the default behavior (and remove ignore_order) should be safe. Either making it default behavior or stay as it is and apply ignore_order=True on demand both fine for me. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

@mattwang44 are translators able to re-order any of the other ones?

Copy link
Contributor Author

@mattwang44 mattwang44 Dec 4, 2025

Choose a reason for hiding this comment

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

i believe so, but chances are rare.

@AA-Turner
Copy link
Member

AA-Turner commented Dec 3, 2025

cc @mattwang44 I want to release a 9.0.4 with this fix, can you have a look at my comments above?

A

mattwang44 and others added 2 commits December 4, 2025 11:16
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
@AA-Turner
Copy link
Member

@mattwang44 can you add a CHANGES entry?

A

@AA-Turner AA-Turner merged commit 88a4a97 into sphinx-doc:master Dec 4, 2025
52 of 53 checks passed
@mattwang44 mattwang44 deleted the refine-compare-references-method branch December 4, 2025 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positive warnings for reordered refs and translated display text

2 participants