Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jan 16, 2025
1 parent 623962e commit 9fb683b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Features added
Bugs fixed
----------

* #12463: ``autosummary`` ignores ``__all__`` when it is empty.
* #12463: autosummary: Respect an empty module ``__all__``.
Patch by Valentin Pratz
* #13060: HTML Search: use ``Map`` to store per-file term scores.
Patch by James Addison
Expand Down
9 changes: 5 additions & 4 deletions sphinx/ext/autosummary/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,11 @@ def members_of(obj: Any, conf: Config) -> Sequence[str]:
if conf.autosummary_ignore_module_all:
return dir(obj)
else:
all = getall(obj)
# if __all__ is not set, return dir, but __all__ might also be an
# empty list, so do not use `return getall(obj) or dir(obj)`.
return dir(obj) if all is None else all
if (obj___all__ := getall(obj)) is not None:
# return __all__, even if empty.
return obj___all__
# if __all__ is not set, return dir(obj)
return dir(obj)


def generate_autosummary_content(
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__all__ = []
__all__ = ()
4 changes: 1 addition & 3 deletions tests/roots/test-ext-autosummary-module_empty_all/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autodoc', 'sphinx.ext.autosummary']
autodoc_default_options = {
'members': True,
}
autodoc_default_options = {'members': True}
autosummary_ignore_module_all = False
autosummary_imorted_members = False

Expand Down
35 changes: 15 additions & 20 deletions tests/test_extensions/test_ext_autosummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,8 @@ def test_autosummary_module_all(app):
app.build()
# generated/foo is generated successfully
assert app.env.get_doctree('generated/autosummary_dummy_package_all')
module = (
app.srcdir / 'generated' / 'autosummary_dummy_package_all.rst'
).read_text(encoding='utf8')
path = app.srcdir / 'generated' / 'autosummary_dummy_package_all.rst'
module = path.read_text(encoding='utf8')
assert ' .. autosummary::\n \n PublicBar\n \n' in module
assert (
' .. autosummary::\n \n public_foo\n public_baz\n \n'
Expand All @@ -846,24 +845,20 @@ def test_autosummary_module_empty_all(app):
app.build()
# generated/foo is generated successfully
assert app.env.get_doctree('generated/autosummary_dummy_package_empty_all')
module = (
app.srcdir / 'generated' / 'autosummary_dummy_package_empty_all.rst'
).read_text(encoding='utf8')
path = app.srcdir / 'generated' / 'autosummary_dummy_package_empty_all.rst'
module = path.read_text(encoding='utf8')
assert '.. automodule:: autosummary_dummy_package_empty_all' in module
# for __all__ = [], the output should not contain any variables
for name in [
'__all__',
'__builtins__',
'__cached__',
'__doc__',
'__file__',
'__loader__',
'__name__',
'__package__',
'__path__',
'__spec__',
]:
assert name not in module
# for __all__ = (), the output should not contain any variables
assert '__all__' not in module
assert '__builtins__' not in module
assert '__cached__' not in module
assert '__doc__' not in module
assert '__file__' not in module
assert '__loader__' not in module
assert '__name__' not in module
assert '__package__' not in module
assert '__path__' not in module
assert '__spec__' not in module
finally:
sys.modules.pop('autosummary_dummy_package_all', None)

Expand Down

0 comments on commit 9fb683b

Please sign in to comment.