Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sphinx/ext/autodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,14 @@ def is_filtered_inherited_member(name: str, obj: Any) -> bool:
has_doc = bool(doc)

metadata = extract_metadata(doc)
attr_doc = attr_docs.get((namespace, membername))
if attr_doc:
if isinstance(attr_doc, (list, tuple)):
attr_doc = '\n'.join(attr_doc)
attr_metadata = extract_metadata(attr_doc)
if attr_metadata:
metadata = {**attr_metadata, **metadata}

if 'private' in metadata:
# consider a member private if docstring has "private" metadata
isprivate = True
Expand Down
2 changes: 2 additions & 0 deletions tests/roots/test-ext-autodoc/target/meta_doc_comments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#: :meta public:
_foo = None
17 changes: 17 additions & 0 deletions tests/test_ext_autodoc_attr_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
test_ext_autodoc_attr_metadata
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Tests for autodoc behavior around metadata in attribute doc comments.
"""

import pytest

from .test_ext_autodoc import do_autodoc


@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_meta_public_doc_comment(app):
options = {"members": None}
actual = do_autodoc(app, 'module', 'target.meta_doc_comments', options)
assert '.. py:data:: _foo' in list(actual)