Skip to content

Comments

fix: keep autodoc type alias docstrings#77

Open
casey-brooks wants to merge 2 commits intosphinx-doc__sphinx-9229from
fix/type-alias-docstrings-ast-constant
Open

fix: keep autodoc type alias docstrings#77
casey-brooks wants to merge 2 commits intosphinx-doc__sphinx-9229from
fix/type-alias-docstrings-ast-constant

Conversation

@casey-brooks
Copy link

Summary

  • handle ast.Constant string literals when picking up variable docstrings
  • add regression fixtures exercising alias docstrings under simulated Python 3.14 behavior
  • cover behaviour with a new autodoc test that monkeypatches ast.Str and asserts docstrings are emitted

Testing

  • PYTHONPATH=/workspace/sphinx .venv/bin/pytest tests/test_ext_autodoc_autodata.py -k type_alias_docstring -q
  • PYTHONPATH=/workspace/sphinx .venv/bin/flake8 sphinx/pycode/parser.py tests/test_ext_autodoc_autodata.py tests/roots/test-ext-autodoc-typealias

Resolves #71

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

Test & Lint Summary

  • PYTHONPATH=/workspace/sphinx .venv/bin/pytest tests/test_ext_autodoc_autodata.py -k type_alias_docstring -q (1 passed, 0 failed, 8 deselected)
  • .venv/bin/flake8 sphinx/pycode/parser.py tests/test_ext_autodoc_autodata.py tests/roots/test-ext-autodoc-typealias (no issues)

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 tackling the Constant/Str regression and adding coverage. I left blocking notes on the new fixtures: the module currently relies on Python 3.7+/3.10+ syntax (from __future__ import annotations, TypeAlias, and the PEP 604 unions). Because the branch still supports Python 3.6–3.9, the testroot would fail to import there. Please adjust the fixtures to stay compatible with the supported interpreter range.

@casey-brooks
Copy link
Author

Updated the fixture to avoid Python 3.10+ syntax: dropped the future annotations import, swapped the usage for standard unions, and reran the focused autodoc test + flake8.

@casey-brooks
Copy link
Author

Updated the fixture to avoid Python 3.10+ syntax: dropped the future annotations import, swapped the TypeAlias usage for standard Optional[...] unions, and reran the focused autodoc test + flake8.

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.

Looks great—thanks for backporting the fixture to older interpreters.

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