Fix: instance variables link to other variables of the same name#14389
Closed
piyushhhxyz wants to merge 1 commit intosphinx-doc:masterfrom
Closed
Fix: instance variables link to other variables of the same name#14389piyushhhxyz wants to merge 1 commit intosphinx-doc:masterfrom
piyushhhxyz wants to merge 1 commit intosphinx-doc:masterfrom
Conversation
Instance variables documented with :var:, :ivar:, or :cvar: had their names automatically turned into cross-references (using rolename='obj'), which caused them to link to unrelated variables with the same name elsewhere in the project. The fix removes rolename='obj' from the 'variable' PyTypedField definition so variable names are no longer wrapped in pending_xref nodes. The type annotations (typerolename='class') are preserved, so variable types are still cross-referenced. Fixes sphinx-doc#8638
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removes
rolename='obj'from the'variable'PyTypedFielddefinition insphinx/domains/python.pyso that variable names documented with:var:,:ivar:, or:cvar:are no longer automatically turned into cross-reference links.Problem
When using autodoc (especially via apidoc), instance variables documented with
:ivar:or:var:had their names automatically wrapped inpending_xrefnodes with roleobj. This caused Sphinx's cross-reference resolution (including fuzzy matching infind_obj) to link them to completely unrelated variables with the same name elsewhere in the project.For example,
somepackage.subA.Foo.limitwould auto-link tosomepackage.subB.Bar.limiteven though they are completely unrelated.Fix
Removed
rolename='obj'from the variable field type definition:The
typerolename='class'is preserved, so variable types are still cross-referenced as expected. Only the variable names stop being auto-linked.Fixes #8638