Skip to content

Commit

Permalink
Fix #8219: autodoc: Parameters for generic base class are not shown
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Oct 4, 2020
1 parent a8abb99 commit c204c7f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -42,6 +42,8 @@ Bugs fixed
* #8157: autodoc: TypeError is raised when annotation has invalid __args__
* #7964: autodoc: Tuple in default value is wrongly rendered
* #8200: autodoc: type aliases break type formatting of autoattribute
* #8219: autodoc: Parameters for generic class are not shown when super class is
a generic class and show-inheritance option is given
* #8192: napoleon: description is disappeared when it contains inline literals
* #8142: napoleon: Potential of regex denial of service in google style docs
* #8169: LaTeX: pxjahyper loaded even when latex_engine is not platex
Expand Down
33 changes: 26 additions & 7 deletions sphinx/ext/autodoc/__init__.py
Expand Up @@ -1514,13 +1514,32 @@ def add_directive_header(self, sig: str) -> None:
if not self.doc_as_attr and self.options.show_inheritance:
sourcename = self.get_sourcename()
self.add_line('', sourcename)
if hasattr(self.object, '__bases__') and len(self.object.__bases__):
bases = [':class:`%s`' % b.__name__
if b.__module__ in ('__builtin__', 'builtins')
else ':class:`%s.%s`' % (b.__module__, b.__qualname__)
for b in self.object.__bases__]
self.add_line(' ' + _('Bases: %s') % ', '.join(bases),
sourcename)

def restify(cls: "Type") -> str:
"""Convert class to reST text."""
if cls.__module__ in ('__builtin__', 'builtins'):
return ':class:`%s`' % cls.__name__
elif inspect.isgenericalias(cls):
if cls._name:
text = ':class:`%s.%s`' % (cls.__module__, cls._name)
else:
text = restify(cls.__origin__)

if cls.__args__:
text += r"\ [%s]" % ", ".join(restify(a) for a in cls.__args__)
return text
elif hasattr(cls, '__qualname__'):
return ':class:`%s.%s`' % (cls.__module__, cls.__qualname__)
else:
# not a class (ex. TypeVar)
return ':obj:`%s.%s`' % (cls.__module__, cls.__name__)

if hasattr(self.object, '__orig_bases__') and len(self.object.__orig_bases__):
bases = [restify(cls) for cls in self.object.__orig_bases__]
self.add_line(' ' + _('Bases: %s') % ', '.join(bases), sourcename)
elif hasattr(self.object, '__bases__') and len(self.object.__bases__):
bases = [restify(cls) for cls in self.object.__bases__]
self.add_line(' ' + _('Bases: %s') % ', '.join(bases), sourcename)

def get_doc(self, encoding: str = None, ignore: int = None) -> List[List[str]]:
if encoding is not None:
Expand Down

0 comments on commit c204c7f

Please sign in to comment.