Repository: Chilipp/autodocsumm

Issue:
Alias Expands Nested Class Documentation
Assigning a type to a class attribute is documented as an alias, but its nested class members are being expanded.

```py
class NestedClass:
    """Parent class"""
    class Foo:
        """Nested class"""
        def foo(self):
            """Nested method"""
            pass

        def bar(self):
            """Nested method"""
            pass

class Attribute:
    """Attribute"""
    #: Alias
    foo = NestedClass.Foo
    #: Attribute
    bar = 'bar'
```

<img width="721" alt="Screen Shot 2022-02-25 at 6 30 14 PM" src="https://user-images.githubusercontent.com/3108007/155820699-26a82d09-3591-4b47-9a8c-0047f1c1d11d.png">

Without autosummary on auto doc does not recurse on aliases:

<img width="326" alt="Screen Shot 2022-02-25 at 6 28 57 PM" src="https://user-images.githubusercontent.com/3108007/155820704-ea14cb71-ecc7-4b6a-95aa-c3f1415fdeda.png">


Discussion:

Patch:
diff --git a/autodocsumm/__init__.py b/autodocsumm/__init__.py
index 5808308..9727ec1 100755
--- a/autodocsumm/__init__.py
+++ b/autodocsumm/__init__.py
@@ -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):


Test patch:
diff --git a/tests/test-root/dummy.py b/tests/test-root/dummy.py
index 36be801..f980498 100644
--- a/tests/test-root/dummy.py
+++ b/tests/test-root/dummy.py
@@ -84,6 +84,14 @@ class TestClassWithInlineAutoClassSumm:
         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'
 
diff --git a/tests/test-root/test_class_with_ref_to_other_class.rst b/tests/test-root/test_class_with_ref_to_other_class.rst
new file mode 100644
index 0000000..4cbb5cf
--- /dev/null
+++ b/tests/test-root/test_class_with_ref_to_other_class.rst
@@ -0,0 +1,6 @@
+Autoclasssumm of Dummy Class
+============================
+
+.. autoclass:: dummy.TestClassWithRefToOtherClass
+    :members:
+    :autosummary:
diff --git a/tests/test_autodocsumm.py b/tests/test_autodocsumm.py
index 1fdcb59..fd16399 100644
--- a/tests/test_autodocsumm.py
+++ b/tests/test_autodocsumm.py
@@ -322,6 +322,22 @@ class TestAutosummaryDocumenter:
 
         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')