Skip to content

Comments

fix: autodoc respects empty __all__ (swev-id: sphinx-doc__sphinx-8595)#64

Open
casey-brooks wants to merge 1 commit intosphinx-doc__sphinx-8595from
fix/autodoc-empty-all
Open

fix: autodoc respects empty __all__ (swev-id: sphinx-doc__sphinx-8595)#64
casey-brooks wants to merge 1 commit intosphinx-doc__sphinx-8595from
fix/autodoc-empty-all

Conversation

@casey-brooks
Copy link

Summary

  • treat __all__ = [] as an explicit empty export set rather than falling back to implicit members
  • document new fixture module exercising empty __all__ and expand autodoc tests for default, explicit, and ignore-module-all flows
  • ensure :members: honours explicit names even when __all__ is empty while :ignore-module-all: still lists public members

Testing

  • ./.venv/bin/pytest -k 'empty_all'

Issue

Reproduction (before fix)

  1. Create empty_all.py with __all__ = [] and three functions (foo, bar, baz).
  2. Create a minimal docs project with .. automodule:: empty_all and :members:.
  3. Build with sphinx-build -b html docs build-html using the base branch.

Observed output (pre-fix):

<dt id="empty_all.bar">...bar() -> None</dt>
<dt id="empty_all.baz">...baz() -> None</dt>
<dt id="empty_all.foo">...foo() -> None</dt>

Expected output (post-fix):

  • Default :members: emits no functions when __all__ is explicitly empty.
  • Explicit :members: foo,baz still documents foo and baz.
  • Adding :ignore-module-all: restores the public function listings.

Environment

  • Python 3.12.3
  • docutils 0.20.1
  • Jinja2 3.0.3
  • sphinxcontrib-applehelp 1.0.2
  • sphinxcontrib-devhelp 1.0.2
  • sphinxcontrib-htmlhelp 1.0.2
  • sphinxcontrib-qthelp 1.0.3
  • sphinxcontrib-serializinghtml 1.1.5

CI

  • Not triggering CI manually per instructions.

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

Local Validation

  • ============================= test session starts ==============================
    platform linux -- Python 3.12.3, pytest-9.0.2, pluggy-1.6.0
    libraries: Sphinx-3.5.0+/c537379e0, docutils-0.20.1
    base tempdir: /tmp/pytest-of-root/pytest-7
    rootdir: /workspace/sphinx
    configfile: setup.cfg
    testpaths: tests
    plugins: cov-7.0.0
    collected 1642 items / 1642 deselected / 0 selected

=============================== warnings summary ===============================
sphinx/util/docutils.py:45
/workspace/sphinx/sphinx/util/docutils.py:45: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
version_info = tuple(LooseVersion(docutils.version).version)

sphinx/registry.py:22
/workspace/sphinx/sphinx/registry.py:22: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
from pkg_resources import iter_entry_points

.venv/lib/python3.12/site-packages/pkg_resources/init.py:3146
.venv/lib/python3.12/site-packages/pkg_resources/init.py:3146
.venv/lib/python3.12/site-packages/pkg_resources/init.py:3146
.venv/lib/python3.12/site-packages/pkg_resources/init.py:3146
.venv/lib/python3.12/site-packages/pkg_resources/init.py:3146
.venv/lib/python3.12/site-packages/pkg_resources/init.py:3146
/workspace/sphinx/.venv/lib/python3.12/site-packages/pkg_resources/init.py:3146: DeprecationWarning: Deprecated call to pkg_resources.declare_namespace('sphinxcontrib').
Implementing implicit namespace packages (as specified in PEP 420) is preferred to pkg_resources.declare_namespace. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
declare_namespace(pkg)

sphinx/directives/patches.py:14
/workspace/sphinx/sphinx/directives/patches.py:14: DeprecationWarning: The docutils.parsers.rst.directive.html module will be removed in Docutils 2.0. Since Docutils 0.18, the "Meta" node is defined in docutils.parsers.rst.directives.misc.
from docutils.parsers.rst.directives import html, images, tables

sphinx/util/rst.py:55
/workspace/sphinx/sphinx/util/rst.py:55: DeprecationWarning: 'environmentfilter' is renamed to 'pass_environment', the old name will be removed in Jinja 3.1.
@environmentfilter

sphinx/util/images.py:12
/workspace/sphinx/sphinx/util/images.py:12: DeprecationWarning: 'imghdr' is deprecated and slated for removal in Python 3.13
import imghdr

sphinx/jinja2glue.py:105
/workspace/sphinx/sphinx/jinja2glue.py:105: DeprecationWarning: 'contextfunction' is renamed to 'pass_context', the old name will be removed in Jinja 3.1.
@contextfunction

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
==================== 1642 deselected, 12 warnings in 0.37s ===================== (3 passed, 1639 deselected)

  • \ (no issues)

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 good. Treating an explicit empty all as a real export list keeps autodoc from falling back to implicit members, and the new regression tests cover the default, explicit, and ignore-module-all flows.

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