Skip to content

Comments

fix: propagate docfield scope (swev-id: sphinx-doc__sphinx-8551)#59

Open
casey-brooks wants to merge 2 commits intosphinx-doc__sphinx-8551from
casey/fix-process-field-xref
Open

fix: propagate docfield scope (swev-id: sphinx-doc__sphinx-8551)#59
casey-brooks wants to merge 2 commits intosphinx-doc__sphinx-8551from
casey/fix-process-field-xref

Conversation

@casey-brooks
Copy link

Summary

  • add PythonDomain.process_field_xref to attach module/class context for docfield xrefs
  • ensure implicit types emitted by :type:/:rtype: resolve respecting currentmodule/class scope

Issue

Reproduction (pre-fix)

  1. Create docs/index.rst with:
    .. py:class:: mod.A
    .. py:class:: mod.submod.A
    
    .. py:function:: f()
    
        - :py:class:`mod.A`
        - :py:class:`mod.submod.A`
    
        :param mod.A a:
        :param mod.submod.A b:
        :rtype: mod.A
        :rtype: mod.submod.A
    
    .. py:currentmodule:: mod
    
    .. py:function:: f()
    
        - :py:class:`A`
        - :py:class:`mod.A`
        - :py:class:`mod.submod.A`
    
        :param A a:
        :param mod.A b:
        :param mod.submod.A c:
        :rtype: A
        :rtype: mod.A
        :rtype: mod.submod.A
    
    .. py:currentmodule:: mod.submod
    
    .. py:function:: f()
    
        - :py:class:`A`
        - :py:class:`mod.A`
        - :py:class:`mod.submod.A`
    
        :param A a: BUG: links to mod.A instead of mod.submod.A
        :param mod.A b:
        :param mod.submod.A c:
        :rtype: A
        :rtype: mod.A
        :rtype: mod.submod.A
  2. Run sphinx-build -n -b html docs _build/html
  3. Observed warnings (build log lines, no stack traces):
    index.rst:28: WARNING: more than one target found for cross-reference 'A': mod.A, mod.submod.A
    index.rst:28: WARNING: more than one target found for cross-reference 'A': mod.A, mod.submod.A
    index.rst:42: WARNING: more than one target found for cross-reference 'A': mod.A, mod.submod.A
    index.rst:42: WARNING: more than one target found for cross-reference 'A': mod.A, mod.submod.A
    

Validation (post-fix)

  • sphinx-build -n -b html docs _build/html → succeeds with no warnings; _build/html/index.html now links unqualified A under .. py:currentmodule:: mod.submod to #mod.submod.A
  • pytest -k 'domain and python'

Environment notes

  • Python 3.11 virtualenv with Jinja2==3.0.3, MarkupSafe==2.0.1, docutils==0.16, html5lib==1.1, and pinned sphinxcontrib-* versions per branch requirements

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

Test & Lint Summary

  • .venv/bin/flake8 sphinx/domains/python.py
  • .venv/bin/pytest -k 'domain and python'
  • .venv/bin/sphinx-build -n -b html docs _build/html (with the issue repro docs snippet)

Results:

  • Flake8: no findings.
  • Pytest: 1 passed, 1631 deselected.
  • Sphinx build: succeeds with 0 warnings post-fix.

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 scope propagation change looks good, but the test suite still assumes docfield xrefs lack any module/class context. Please update/add tests so we both keep the suite green and capture the regression described in #56.

@casey-brooks
Copy link
Author

Test & Lint Summary (update)

  • .venv/bin/flake8 sphinx/domains/python.py tests/test_domain_py.py
  • .venv/bin/pytest -k 'domain and python'

Results:

  • Flake8: no findings.
  • Pytest: 1 passed, 1633 deselected.

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.

Thanks for the follow-up! The updated expectations in and the new focused regression tests cover the docfield scope propagation nicely. Everything looks good on my end.

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