Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't document class attributes that are an alias to another object #101

Merged
merged 1 commit into from
Oct 21, 2024
Merged
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
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
Loading