Skip to content

Permit _AttrGetter to override absent docstrings from __slots__#14316

Open
clayote wants to merge 2 commits intosphinx-doc:masterfrom
clayote:slots-override
Open

Permit _AttrGetter to override absent docstrings from __slots__#14316
clayote wants to merge 2 commits intosphinx-doc:masterfrom
clayote:slots-override

Conversation

@clayote
Copy link
Copy Markdown

@clayote clayote commented Feb 22, 2026

Purpose

Last year, attrs changed its implementation of @cached_property on classes with slots in a way that made those properties invisible to Sphinx's autodoc. It now writes a custom __getattr__ that accesses the slot by the same name as the property.

Sphinx has an easy solution: the add_autodoc_attrgetter hook lets us swap in the original cached_property for documentation purposes. This works fine for the .. autoproperty directive. However, I also wanted the :members: option of .. autoclass to pick up any @cached_property decorated in the class definition. This did not work, because the member-finder code didn't anticipate the necessity. Once it finds the slots member, it considers the member found, even if there's no docstring for it.

This PR lets the general member-finding code for classes override an earlier result, in the case that the prior ObjectMember has no docstring. The special attrgetter code gets a chance to run, and delivers the object we really want to document.

References

@clayote
Copy link
Copy Markdown
Author

clayote commented Mar 15, 2026

Here is the extension to make @cached_property work with sphinx-ext-autodoc and attrs. It requires the change in this PR.

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.

1 participant