diff --git a/CHANGES b/CHANGES index ad1436925..70c9f53c0 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,7 @@ Bugs fixed * #1922: html search: Upper characters problem in French * #4412: Updated jQuery version from 3.1.0 to 3.2.1 * #4438: math: math with labels with whitespace cause html error +* #2437: make full reference for classes, aliased with "alias of" Testing -------- diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index bd686644c..1ccd74647 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -1513,8 +1513,14 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type: def add_content(self, more_content, no_docstring=False): # type: (Any, bool) -> None if self.doc_as_attr: - classname = safe_getattr(self.object, '__name__', None) + classname = safe_getattr(self.object, '__qualname__', None) + if not classname: + classname = safe_getattr(self.object, '__name__', None) if classname: + module = safe_getattr(self.object, '__module__', None) + parentmodule = safe_getattr(self.parent, '__module__', None) + if module and module != parentmodule: + classname = str(module) + u'.' + str(classname) content = ViewList( [_('alias of :class:`%s`') % classname], source='') ModuleLevelDocumenter.add_content(self, content, diff --git a/tests/roots/test-ext-autodoc/autodoc_dummy_bar.py b/tests/roots/test-ext-autodoc/autodoc_dummy_bar.py new file mode 100644 index 000000000..d79d1691f --- /dev/null +++ b/tests/roots/test-ext-autodoc/autodoc_dummy_bar.py @@ -0,0 +1,5 @@ +from bug2437.autodoc_dummy_foo import Foo + +class Bar(object): + """Dummy class Bar with alias.""" + my_name = Foo diff --git a/tests/roots/test-ext-autodoc/bug2437/__init__.py b/tests/roots/test-ext-autodoc/bug2437/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/roots/test-ext-autodoc/bug2437/autodoc_dummy_foo.py b/tests/roots/test-ext-autodoc/bug2437/autodoc_dummy_foo.py new file mode 100644 index 000000000..b578a2255 --- /dev/null +++ b/tests/roots/test-ext-autodoc/bug2437/autodoc_dummy_foo.py @@ -0,0 +1,3 @@ +class Foo(object): + """Dummy class Foo.""" + pass diff --git a/tests/roots/test-ext-autodoc/conf.py b/tests/roots/test-ext-autodoc/conf.py index 01e6dcc75..9f026eb8d 100644 --- a/tests/roots/test-ext-autodoc/conf.py +++ b/tests/roots/test-ext-autodoc/conf.py @@ -10,3 +10,5 @@ source_suffix = '.rst' autodoc_mock_imports = [ 'dummy' ] + +nitpicky = True diff --git a/tests/roots/test-ext-autodoc/contents.rst b/tests/roots/test-ext-autodoc/contents.rst index b808eafda..ce4302204 100644 --- a/tests/roots/test-ext-autodoc/contents.rst +++ b/tests/roots/test-ext-autodoc/contents.rst @@ -1,3 +1,9 @@ .. automodule:: autodoc_dummy_module :members: + +.. automodule:: bug2437.autodoc_dummy_foo + :members: + +.. automodule:: autodoc_dummy_bar + :members: diff --git a/tests/test_ext_autodoc.py b/tests/test_ext_autodoc.py index e7057df0f..7a9666792 100644 --- a/tests/test_ext_autodoc.py +++ b/tests/test_ext_autodoc.py @@ -22,3 +22,13 @@ def test_autodoc(app, status, warning): assert isinstance(content[3], addnodes.desc) assert content[3][0].astext() == 'autodoc_dummy_module.test' assert content[3][1].astext() == 'Dummy function using dummy.*' + + # issue sphinx-doc/sphinx#2437 + assert content[11][-1].astext() == """Dummy class Bar with alias. + + + +my_name + +alias of bug2437.autodoc_dummy_foo.Foo""" + assert warning.getvalue() == ''