Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #8180: Docstring metadata ignored for attributes #10447

Closed
wants to merge 3 commits into from

Conversation

akruis
Copy link

@akruis akruis commented May 13, 2022

Feature or Bugfix

  • Bugfix

Purpose

Detail

  • The change adds two tests in test_ext_autodoc_private_members: test_private_attributes and test_private_attributes_and_private_members. Both are modeled analog to existing test cases for :meta private: and :meta public: for functions and module variables.
  • About the fix: Currently the decision logic in autodoc.Documenter.filter_members does not see the docstring of class attributes. Therefore the fix must make the docstring available. For variables of a module ("global variables") the docstring is stored in ObjectMember.docstring (see ModuleDocumenter.get_module_members()). autodoc.Documenter.filter_members retrieves the docstring from the ObjectMember object. For class attributes, the ObjectMember does not contain the docstring, because autodoc.importer.get_class_members does not set it, when it creates the ObjectMember object. My fix changes autodoc.importer.get_class_members to set the docstring.
  • Rejected alternatives: Issue Docstring metadata ignored for attributes #8180 contains a patch, that modifies autodoc.Documenter.filter_members. This patch also fixes the bug, but is makes the information flow more complicated. Currently autodoc.Documenter.filter_members uses just two ways to get the docstring of a member: as the result of sphinx.util.inspect.getdoc or from ObjectMember.docstring. The patch would add a third way: using analyzer.find_attr_docs().

Relates

Anselm Kruis added 3 commits May 13, 2022 12:14
The test checks, if ":meta private:" and ":meta public:" have an effect
in attributes of a class. Currently the new test cases fail.
The fix is in the next commit.
Change ext.autodoc.importer.get_class_members to set
ObjectMember.docstring the docstring found by the source code
analyzer.
@tk0miya
Copy link
Member

tk0miya commented May 22, 2022

Now I merged this manually into the 5.0.x branch. It will be released as v5.0 next weekend. Thank you for your work!

@tk0miya tk0miya closed this May 22, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants