Skip to content

Comments

swev-id: sphinx-doc__sphinx-8638 Prevent spurious variable xrefs#69

Open
casey-brooks wants to merge 2 commits intosphinx-doc__sphinx-8638from
feature/disable-auto-xref-for-ivar
Open

swev-id: sphinx-doc__sphinx-8638 Prevent spurious variable xrefs#69
casey-brooks wants to merge 2 commits intosphinx-doc__sphinx-8638from
feature/disable-auto-xref-for-ivar

Conversation

@casey-brooks
Copy link

Summary

  • add the python_docstring_variable_xrefs config flag so projects can disable auto cross-references for :var:/ :ivar:/ :cvar:
  • make the Python docstring variable field emit literals when disabled while preserving type cross references
  • cover the behavior with new docdomain tests and an integration fixture

Reproduction Steps

  1. Clone https://github.com/13steinj/sphinx-issue-examples and checkout the referenced_variables branch.
  2. Build the docs with the default configuration: sphinx-build -b html docs _build/html.
  3. Open _build/html/index.html and inspect the Attributes section for Sample.foo.

Observed: the attribute name links to the unrelated foo() function. (Stack trace: not applicable; this is a behavioral regression.)

Testing

  • source .venv/bin/activate && PYTHONPATH=/workspace/sphinx pytest tests/test_domain_py.py -q
  • source .venv/bin/activate && flake8 sphinx/domains/python.py tests/test_domain_py.py

Resolves #66

@casey-brooks casey-brooks requested a review from a team December 26, 2025 18:20
@casey-brooks
Copy link
Author

Test & Lint Summary

  • source .venv/bin/activate && PYTHONPATH=/workspace/sphinx pytest tests/test_domain_py.py -q
    • 37 passed, 0 failed, 0 skipped
  • source .venv/bin/activate && flake8 sphinx/domains/python.py tests/test_domain_py.py
    • no lint errors

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

The implementation and tests look good, but the new configuration option needs to be documented so users can discover and understand it.

@casey-brooks
Copy link
Author

Documentation update pushed:

  • documented :confval:python_docstring_variable_xrefs in the configuration reference with usage example and behaviour notes
  • added autodoc guidance about toggling docstring variable cross-references and recorded the change in CHANGES
  • built the HTML docs locally to confirm a clean build

Doc Build

  • source .venv/bin/activate && make -C doc html
    • build succeeded with no warnings after installing sphinxcontrib-websupport==1.2.4 and graphviz via nix

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

Documentation looks great now. Thanks for the quick follow-up!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants