Skip to content

Commit e4319d4

Browse files
committed
don't document class attributes that are an alias of another class
1 parent 354e67b commit e4319d4

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

autodocsumm/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,11 @@ class AutoSummClassDocumenter(ClassDocumenter, AutosummaryDocumenter):
414414
def add_content(self, *args, **kwargs):
415415
super().add_content(*args, **kwargs)
416416

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

419423

420424
class CallableDataDocumenter(DataDocumenter):

tests/test-root/dummy.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ def test_method_of_inline_test(self):
8484
pass
8585

8686

87+
class TestClassWithRefToOtherClass:
88+
"""Class test for the autodocsummary when a class attribute is a reference
89+
to another class. No autosummary of the class should be generated for
90+
the attribute. See also issue #69"""
91+
92+
foo = TestClass
93+
94+
8795
#: data to be skipped
8896
large_data = 'Should also be skipped'
8997

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Autoclasssumm of Dummy Class
2+
============================
3+
4+
.. autoclass:: dummy.TestClassWithRefToOtherClass
5+
:members:
6+
:autosummary:

tests/test_autodocsumm.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,22 @@ def test_class_nosignatures(self, app):
322322

323323
assert '()' not in html
324324

325+
def test_class_no_summary_for_reference_to_class(self, app):
326+
# see also: issue #69
327+
app.build()
328+
329+
html = get_html(app, 'test_class_with_ref_to_other_class.html')
330+
331+
# assert that the class itself has an autosummary that contains its
332+
# attributes
333+
assert in_autosummary("foo", html)
334+
335+
# Assert that there is no autosummary of the attribute that is an alias
336+
# of another class. This autosummary would contain attrs/methods/...
337+
# of the referenced class.
338+
assert not in_autosummary("test_method", html)
339+
assert not in_autosummary("test_attr", html)
340+
325341
def test_inherited(self, app):
326342
app.build()
327343
html = get_html(app, 'test_inherited.html')

0 commit comments

Comments
 (0)