diff --git a/CHANGES b/CHANGES index 600efc4667c..410fb11422b 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 434fc40e947..d6e22849ea0 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -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: