Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inheritance infos to the class pages. #637

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pydoctor/model.py
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions pydoctor/templatewriter/pages/__init__.py
Original file line number Diff line number Diff line change
@@ -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 informational
tristanlatr marked this conversation as resolved.
Show resolved Hide resolved
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"
13 changes: 13 additions & 0 deletions pydoctor/themes/base/apidocs.css
Original file line number Diff line number Diff line change
@@ -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;
}