mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #8493: Use restify() in autodoc to reference alias attributes
This commit is contained in:
parent
5a0e1231ad
commit
ccfd98dc07
1
CHANGES
1
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
|
||||
--------
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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) == [
|
||||
|
Loading…
Reference in New Issue
Block a user