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
2 changes: 1 addition & 1 deletion sphinx/ext/autodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ def get_module_members(self) -> Dict[str, ObjectMember]:
def get_object_members(self, want_all: bool) -> Tuple[bool, ObjectMembers]:
members = self.get_module_members()
if want_all:
if not self.__all__:
if self.__all__ is None:
# for implicit module members, check __module__ to avoid
# documenting imported objects
return True, list(members.values())
Expand Down
15 changes: 15 additions & 0 deletions tests/roots/test-ext-autodoc/target/empty_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Module with explicit empty __all__ for autodoc tests."""

__all__ = []


def foo() -> None:
"""Foo function for autodoc."""


def bar() -> None:
"""Bar function for autodoc."""


def baz() -> None:
"""Baz function for autodoc."""
29 changes: 29 additions & 0 deletions tests/test_ext_autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,35 @@ def test_autodoc_imported_members(app):
assert '.. py:function:: save_traceback(app: Sphinx) -> str' in actual


@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_module_with_explicit_empty_all(app):
options = {"members": None}
actual = do_autodoc(app, 'module', 'target.empty_all', options)
assert list(filter(lambda l: 'function::' in l, actual)) == []


@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_module_explicit_members_with_empty_all(app):
options = {"members": "foo,baz"}
actual = do_autodoc(app, 'module', 'target.empty_all', options)
assert list(filter(lambda l: 'function::' in l, actual)) == [
'.. py:function:: baz() -> None',
'.. py:function:: foo() -> None',
]


@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_module_ignore_empty_all(app):
options = {"members": None,
"ignore-module-all": None}
actual = do_autodoc(app, 'module', 'target.empty_all', options)
assert list(filter(lambda l: 'function::' in l, actual)) == [
'.. py:function:: bar() -> None',
'.. py:function:: baz() -> None',
'.. py:function:: foo() -> None',
]


@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_special_members(app):
# specific special methods
Expand Down