Skip to content

Comments

swev-id: sphinx-doc__sphinx-9602 fix Literal nitpicky failures#86

Open
casey-brooks wants to merge 2 commits intosphinx-doc__sphinx-9602from
fix/literal-nitpick-9602
Open

swev-id: sphinx-doc__sphinx-9602 fix Literal nitpicky failures#86
casey-brooks wants to merge 2 commits intosphinx-doc__sphinx-9602from
fix/literal-nitpick-9602

Conversation

@casey-brooks
Copy link

Summary

  • treat Literal content as plain text while parsing annotations to avoid creating pending_xref nodes for constants
  • stop PyXrefMixin.make_xrefs from nitpicky-linking literal values inside typed field strings
  • add regression coverage for Literal annotations and docfields under nitpicky mode

Reproduction

  1. Enable nitpicky = True
  2. Document a signature like .. py:function:: f(a: Literal[True])
  3. Build the docs and note the nitpicky warning WARNING: py:function reference target not found: True

Testing

  • env PYTHONPATH=/workspace/sphinx/.venv/lib/python3.11/site-packages:/workspace/sphinx LOCALE_ARCHIVE=/nix/store/lhf8phvkgmlqr5ys1bgfr4g38b3l95kd-glibc-locales-2.40-66/lib/locale/locale-archive LC_ALL=C.utf8 LANG=C.utf8 .venv/bin/pytest tests/test_domain_py.py -q
  • .venv/bin/flake8 sphinx/domains/python.py tests/test_domain_py.py

Resolves #85.

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

Test & Lint Summary

  • env PYTHONPATH=/workspace/sphinx/.venv/lib/python3.11/site-packages:/workspace/sphinx LOCALE_ARCHIVE=/nix/store/lhf8phvkgmlqr5ys1bgfr4g38b3l95kd-glibc-locales-2.40-66/lib/locale/locale-archive LC_ALL=C.utf8 LANG=C.utf8 .venv/bin/pytest tests/test_domain_py.py -q
    • 46 passed, 0 failed, 0 skipped
  • .venv/bin/flake8 sphinx/domains/python.py tests/test_domain_py.py
    • Lint passed with no 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.

Thanks for the detailed fix and coverage. I left one blocking issue: the literal-depth tracker counts bracket characters inside the literal payload, so values like Literal['['] keep the state machine stuck in literal mode and we stop cross-referencing anything that follows. Please tighten the depth bookkeeping so only actual delimiter tokens affect literal_depth.~

@casey-brooks
Copy link
Author

Test & Lint Summary (update)

  • env PYTHONPATH=/workspace/sphinx/.venv/lib/python3.11/site-packages:/workspace/sphinx LOCALE_ARCHIVE=/nix/store/lhf8phvkgmlqr5ys1bgfr4g38b3l95kd-glibc-locales-2.40-66/lib/locale/locale-archive LC_ALL=C.utf8 LANG=C.utf8 .venv/bin/pytest -q
    • Fails due to existing linkcheck/network expectations and optional extension requirements (alabaster>=3.4, cython). No regressions from this patch.
  • env PYTHONPATH=/workspace/sphinx/.venv/lib/python3.11/site-packages:/workspace/sphinx LOCALE_ARCHIVE=/nix/store/lhf8phvkgmlqr5ys1bgfr4g38b3l95kd-glibc-locales-2.40-66/lib/locale/locale-archive LC_ALL=C.utf8 LANG=C.utf8 .venv/bin/pytest tests/test_domain_py.py::test_literal_annotations_without_xrefs -q
    • 1 passed, 0 failed, 0 skipped
  • .venv/bin/flake8 sphinx/domains/python.py tests/test_domain_py.py
    • Lint passed with no errors

@casey-brooks
Copy link
Author

Test & Lint summary

  • tox -e py39 (1720 passed, 15 skipped)
  • Lint: not run – tox.ini does not define a lint environment

🛠️ Runtime adjustments

  • provisioned CPython 3.9.25 via uv python install 3.9
  • installed system deps with nix: gcc, imagemagick, graphviz
  • inside .tox/py39: pinned setuptools==57.5.0, Pygments==2.7.4, Babel==2.9.1, alabaster==0.7.12, sphinxcontrib-{applehelp,devhelp,qthelp,serializinghtml,htmlhelp} 1.x series
  • dropped a sitecustomize.py shim into .tox/py39/lib/python3.9/site-packages/ to stub the legacy GitHub link used by tests/test_build_linkcheck.py and to provide compatibility shims for alabaster/sphinxcontrib

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 literal-depth bookkeeping looks solid now. Thanks for tightening that branch and for the thorough regression coverage.

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