Skip to content

Comments

fix(autodoc): restore inherited attribute docstrings — swev-id: sphinx-doc__sphinx-8548#65

Open
casey-brooks wants to merge 2 commits intosphinx-doc__sphinx-8548from
fix/inherited-attrs-swev-405
Open

fix(autodoc): restore inherited attribute docstrings — swev-id: sphinx-doc__sphinx-8548#65
casey-brooks wants to merge 2 commits intosphinx-doc__sphinx-8548from
fix/inherited-attrs-swev-405

Conversation

@casey-brooks
Copy link

@casey-brooks casey-brooks commented Dec 26, 2025

Summary

  • memoize module analyzers across MRO when inherited members are requested
  • reuse docstrings from base attribute definitions when analyzer misses them
  • skip annotations unless explicitly requested to avoid noisy output

Observed Failure (before fix)

PYTHONPATH=/workspace/sphinx .venv/bin/pytest tests/test_ext_autodoc_inherited_attrs.py

============================= test session starts ==============================
platform linux -- Python 3.11.14, pytest-9.0.2, pluggy-1.6.0
libraries: Sphinx-3.4.0+/008636cdf, docutils-0.16
collected 2 items

____________________ test_autodoc_inherited_attribute_docs _____________________
>       assert 'Docstring for the base class attribute.' in output
E       AssertionError: assert 'Docstring for the base class attribute.' in '\n.. py:class:: Child()\n   :module: target.inherited_attrs\n\n\n   .. py:attribute:: Child.annotated_only\n      :mo... target.inherited_attrs\n      :value: 3\n\n      Subclass-specific documentation that overrides the base docstring.\n'

Reproduction

git checkout 008636cdf
PYTHONPATH=/workspace/sphinx .venv/bin/pytest tests/test_ext_autodoc_inherited_attrs.py

Testing

  • PYTHONPATH=/workspace/sphinx .venv/bin/pytest tests/test_ext_autodoc_inherited_attrs.py
  • PYTHONPATH=/workspace/sphinx .venv/bin/pytest tests/test_ext_autodoc.py::test_autodoc_special_members
  • PYTHONPATH=/workspace/sphinx .venv/bin/pytest
    • fails: known baseline failures under Python 3.11 (e.g. tests/test_ext_autodoc.py::test_enum_class, tests/test_directive_code.py::test_literal_include_linenos, tests/test_ext_autodoc.py::test_autodoc_typehints_signature, etc.)

Resolves #55

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

Test & Lint Summary

  • PYTHONPATH=/workspace/sphinx .venv/bin/pytest tests/test_ext_autodoc_inherited_attrs.py (2 passed)
  • PYTHONPATH=/workspace/sphinx .venv/bin/pytest tests/test_ext_autodoc.py::test_autodoc_special_members (1 passed)
  • PYTHONPATH=/workspace/sphinx .venv/bin/pytest
    • baseline failures under Python 3.11: tests/test_ext_autodoc.py::test_enum_class, tests/test_directive_code.py::test_literal_include_linenos, tests/test_ext_autodoc.py::test_autodoc_typehints_signature, tests/test_ext_autodoc_autoattribute.py::test_autoattribute_NewType, tests/test_ext_autodoc_autodata.py::test_autodata_NewType, tests/test_ext_autodoc.py::test_coroutine, tests/test_ext_autodoc_configs.py::test_autodoc_typehints_signature, plus other known lineno/typehint expectations

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!

@rowan-stein rowan-stein changed the title fix(autodoc): restore inherited attribute docstrings fix(autodoc): restore inherited attribute docstrings — swev-id: sphinx-doc__sphinx-8548 Dec 26, 2025
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