diff --git a/pydoctor/model.py b/pydoctor/model.py index 5b4053814..92a02029b 100644 --- a/pydoctor/model.py +++ b/pydoctor/model.py @@ -585,9 +585,11 @@ def mro(self, include_external:bool=False, include_self:bool=True) -> List[Union if include_external is False: _mro = [o for o in self._mro if not isinstance(o, str)] else: - _mro = self._mro + _mro = self._mro[:] if include_self is False: _mro = _mro[1:] + + # It always returns a copy of the list return _mro @property diff --git a/pydoctor/templatewriter/pages/__init__.py b/pydoctor/templatewriter/pages/__init__.py index 828dda33b..b24011c65 100644 --- a/pydoctor/templatewriter/pages/__init__.py +++ b/pydoctor/templatewriter/pages/__init__.py @@ -382,9 +382,53 @@ def __init__(self, ): super().__init__(ob, template_lookup, docgetter) self.baselists = util.class_members(self.ob) + + def classInheritance(self) -> Optional['Flattenable']: + """ + Returns something only if the class inherits + more than the default object type and there + are more than two bases to show. + """ + def buildInheritance(ultag:Tag, bases:List['model.Class']) -> Tag: + """ + Recusrsive function to create nested lists based on the MRO. + """ + if not bases: + return ultag + last = bases.pop() + if isinstance(last, model.Documentable): + link = tags.code(epydoc2stan.taglink(last, self.page_url)) + else: + link = tags.code(self.ob.docstring_linker.link_to(last, last)) + ultag(tags.li(link)) + if bases: + new_ul = create_ul() + ultag(tags.li(buildInheritance(new_ul, bases))) + return ultag + + # fetch MRO + mro = self.ob.mro(True, False) + # Return None if the MRO is not informative + if not mro: + return None + if mro[-1] == 'object': + mro.pop(-1) + if len(mro) <= 1: + return None + + # Present inheritence in the form of a nested list, just like javadoc. + create_ul = lambda:tags.ul(class_='class-inheritance') + ul = create_ul() + buildInheritance(ul, mro) + return tags.div(tags.p("Inheritance: "), ul, class_="class-inheritance-div") def extras(self) -> List[Tag]: r: List[Tag] = [] + + # Render inheritance infos + _inheritance = self.classInheritance() + if _inheritance: + r.append(_inheritance) sourceHref = util.srclink(self.ob) source: "Flattenable" diff --git a/pydoctor/themes/base/apidocs.css b/pydoctor/themes/base/apidocs.css index 6d7a67d6a..5baa14374 100644 --- a/pydoctor/themes/base/apidocs.css +++ b/pydoctor/themes/base/apidocs.css @@ -1123,3 +1123,16 @@ pre.constant-value { padding: .5em; } .rst-deprecated > .rst-versionmodified{ color:#aa6708; } + +/* CSS for MRO */ +.class-inheritance { + margin-top:0; + border:0; + list-style-type: none; +} +.class-inheritance li{ + padding:0; +} +.class-inheritance-div{ + margin-bottom:15px; +}