From ccfd98dc079e1bfed89cb7a44d538842f0d2912c Mon Sep 17 00:00:00 2001 From: Timo Ludwig Date: Thu, 26 Nov 2020 19:28:28 +0100 Subject: [PATCH] Fix #8493: Use restify() in autodoc to reference alias attributes --- CHANGES | 1 + sphinx/ext/autodoc/__init__.py | 12 ++---------- tests/test_ext_autodoc.py | 4 ++-- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index 3c048a4c2..7915f6579 100644 --- a/CHANGES +++ b/CHANGES @@ -68,6 +68,7 @@ Bugs fixed * #8131: linkcheck: Use GET when HEAD requests cause Too Many Redirects, to accommodate infinite redirect loops on HEAD * #8437: Makefile: ``make clean`` with empty BUILDDIR is dangerous +* #8493: autodoc: references to builtins not working in class aliases Testing -------- diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index dd4686dd0..0c04bd40c 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1654,16 +1654,8 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type: def add_content(self, more_content: Optional[StringList], no_docstring: bool = False ) -> None: if self.doc_as_attr: - 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) + '.' + str(classname) - content = StringList([_('alias of :class:`%s`') % classname], source='') - super().add_content(content, no_docstring=True) + content = StringList([_('alias of %s') % restify(self.object)], source='') + super().add_content(content, no_docstring=True) else: super().add_content(more_content) diff --git a/tests/test_ext_autodoc.py b/tests/test_ext_autodoc.py index 4b18da862..000ddc0c5 100644 --- a/tests/test_ext_autodoc.py +++ b/tests/test_ext_autodoc.py @@ -806,7 +806,7 @@ def test_autodoc_inner_class(app): ' .. py:attribute:: Outer.factory', ' :module: target', '', - ' alias of :class:`builtins.dict`' + ' alias of :class:`dict`' ] actual = do_autodoc(app, 'class', 'target.Outer.Inner', options) @@ -1704,7 +1704,7 @@ def test_autodoc_GenericAlias(app): '.. py:attribute:: T', ' :module: target.genericalias', '', - ' alias of :class:`typing.List`', + ' alias of :class:`List`\\ [:class:`int`]', ] else: assert list(actual) == [