Merge pull request #8494 from timoludwig/alias-of-builtin

Use restify() to reference alias attributes in autodoc
This commit is contained in:
Takeshi KOMIYA
2020-11-28 22:55:27 +09:00
committed by GitHub
3 changed files with 5 additions and 12 deletions

View File

@@ -69,6 +69,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) == [