summaryrefslogtreecommitdiff
path: root/sphinx/ext/autodoc/__init__.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-11-09 02:48:55 +0900
committerGitHub <noreply@github.com>2020-11-09 02:48:55 +0900
commit7db3633778a24c4fc90c8a0ceb2318d6df7cf4e3 (patch)
tree974466008fe9453f5171721c370a984e9f25f014 /sphinx/ext/autodoc/__init__.py
parent5337e3848cce988d18a048aaa7a258b275d67e6d (diff)
parente2bf9166da3e89eb7cbe7abb9c1e47e34351bbf8 (diff)
downloadsphinx-git-7db3633778a24c4fc90c8a0ceb2318d6df7cf4e3.tar.gz
Merge pull request #8231 from tk0miya/8219_params_for_base_generic_class_is_not_shown
Fix #8219: autodoc: Parameters for generic base class are not shown
Diffstat (limited to 'sphinx/ext/autodoc/__init__.py')
-rw-r--r--sphinx/ext/autodoc/__init__.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index a0c5cf61f..1cb8475df 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -37,7 +37,7 @@ from sphinx.util.docstrings import extract_metadata, prepare_docstring
from sphinx.util.inspect import (
evaluate_signature, getdoc, object_description, safe_getattr, stringify_signature
)
-from sphinx.util.typing import stringify as stringify_typehint
+from sphinx.util.typing import restify, stringify as stringify_typehint
if False:
# For type annotation
@@ -1574,13 +1574,16 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
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)
+
+ if hasattr(self.object, '__orig_bases__') and len(self.object.__orig_bases__):
+ # A subclass of generic types
+ # refs: PEP-560 <https://www.python.org/dev/peps/pep-0560/>
+ 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__):
+ # A normal class
+ 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: