Skip to content

Commit

Permalink
don't document class attributes that are an alias of another class
Browse files Browse the repository at this point in the history
  • Loading branch information
theOehrly committed Aug 15, 2024
1 parent 354e67b commit e4319d4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion autodocsumm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,11 @@ class AutoSummClassDocumenter(ClassDocumenter, AutosummaryDocumenter):
def add_content(self, *args, **kwargs):
super().add_content(*args, **kwargs)

self.add_autosummary(relative_ref_paths=True)
# If the class is already documented under another name, Sphinx
# documents it as data/attribute. In this case, we do not want to
# generate an autosummary of the class for the attribute (see #69).
if not self.doc_as_attr:
self.add_autosummary(relative_ref_paths=True)


class CallableDataDocumenter(DataDocumenter):
Expand Down
8 changes: 8 additions & 0 deletions tests/test-root/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ def test_method_of_inline_test(self):
pass


class TestClassWithRefToOtherClass:
"""Class test for the autodocsummary when a class attribute is a reference
to another class. No autosummary of the class should be generated for
the attribute. See also issue #69"""

foo = TestClass


#: data to be skipped
large_data = 'Should also be skipped'

Expand Down
6 changes: 6 additions & 0 deletions tests/test-root/test_class_with_ref_to_other_class.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Autoclasssumm of Dummy Class
============================

.. autoclass:: dummy.TestClassWithRefToOtherClass
:members:
:autosummary:
16 changes: 16 additions & 0 deletions tests/test_autodocsumm.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,22 @@ def test_class_nosignatures(self, app):

assert '()' not in html

def test_class_no_summary_for_reference_to_class(self, app):
# see also: issue #69
app.build()

html = get_html(app, 'test_class_with_ref_to_other_class.html')

# assert that the class itself has an autosummary that contains its
# attributes
assert in_autosummary("foo", html)

# Assert that there is no autosummary of the attribute that is an alias
# of another class. This autosummary would contain attrs/methods/...
# of the referenced class.
assert not in_autosummary("test_method", html)
assert not in_autosummary("test_attr", html)

def test_inherited(self, app):
app.build()
html = get_html(app, 'test_inherited.html')
Expand Down

0 comments on commit e4319d4

Please sign in to comment.