Fix #8493: Use restify() in autodoc to reference alias attributes

This commit is contained in:
Timo Ludwig 2020-11-26 19:28:28 +01:00
parent 5a0e1231ad
commit ccfd98dc07
No known key found for this signature in database
GPG Key ID: 91582F0AC69C1573
3 changed files with 5 additions and 12 deletions

View File

@ -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
--------

View File

@ -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)

View File

@ -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) == [