mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Fix linking to classes (in class tree, and add links on unbound methods).
This commit is contained in:
parent
6dcfa3884d
commit
b7a48300cd
1 changed files with 23 additions and 24 deletions
47
Lib/pydoc.py
47
Lib/pydoc.py
|
@ -342,12 +342,13 @@ TT { font-family: lucida console, lucida typewriter, courier }
|
||||||
return '<a href="%s">%s</a>' % (dict[name], name)
|
return '<a href="%s">%s</a>' % (dict[name], name)
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def classlink(self, object, modname, *dicts):
|
def classlink(self, object, modname):
|
||||||
"""Make a link for a class."""
|
"""Make a link for a class."""
|
||||||
name = classname(object, modname)
|
name = classname(object, modname)
|
||||||
for dict in dicts:
|
if sys.modules.has_key(object.__module__) and \
|
||||||
if dict.has_key(object):
|
getattr(sys.modules[object.__module__], object.__name__) is object:
|
||||||
return '<a href="%s">%s</a>' % (dict[object], name)
|
return '<a href="%s.html#%s">%s</a>' % (
|
||||||
|
object.__module__, object.__name__, name)
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def modulelink(self, object):
|
def modulelink(self, object):
|
||||||
|
@ -405,23 +406,23 @@ TT { font-family: lucida console, lucida typewriter, courier }
|
||||||
|
|
||||||
# ---------------------------------------------- type-specific routines
|
# ---------------------------------------------- type-specific routines
|
||||||
|
|
||||||
def formattree(self, tree, modname, classes={}, parent=None):
|
def formattree(self, tree, modname, parent=None):
|
||||||
"""Produce HTML for a class tree as given by inspect.getclasstree()."""
|
"""Produce HTML for a class tree as given by inspect.getclasstree()."""
|
||||||
result = ''
|
result = ''
|
||||||
for entry in tree:
|
for entry in tree:
|
||||||
if type(entry) is type(()):
|
if type(entry) is type(()):
|
||||||
c, bases = entry
|
c, bases = entry
|
||||||
result = result + '<dt><font face="helvetica, arial"><small>'
|
result = result + '<dt><font face="helvetica, arial"><small>'
|
||||||
result = result + self.classlink(c, modname, classes)
|
result = result + self.classlink(c, modname)
|
||||||
if bases and bases != (parent,):
|
if bases and bases != (parent,):
|
||||||
parents = []
|
parents = []
|
||||||
for base in bases:
|
for base in bases:
|
||||||
parents.append(self.classlink(base, modname, classes))
|
parents.append(self.classlink(base, modname))
|
||||||
result = result + '(' + join(parents, ', ') + ')'
|
result = result + '(' + join(parents, ', ') + ')'
|
||||||
result = result + '\n</small></font></dt>'
|
result = result + '\n</small></font></dt>'
|
||||||
elif type(entry) is type([]):
|
elif type(entry) is type([]):
|
||||||
result = result + '<dd>\n%s</dd>\n' % self.formattree(
|
result = result + '<dd>\n%s</dd>\n' % self.formattree(
|
||||||
entry, modname, classes, c)
|
entry, modname, c)
|
||||||
return '<dl>\n%s</dl>\n' % result
|
return '<dl>\n%s</dl>\n' % result
|
||||||
|
|
||||||
def docmodule(self, object, name=None, mod=None):
|
def docmodule(self, object, name=None, mod=None):
|
||||||
|
@ -505,8 +506,8 @@ TT { font-family: lucida console, lucida typewriter, courier }
|
||||||
|
|
||||||
if classes:
|
if classes:
|
||||||
classlist = map(lambda (key, value): value, classes)
|
classlist = map(lambda (key, value): value, classes)
|
||||||
contents = [self.formattree(
|
contents = [
|
||||||
inspect.getclasstree(classlist, 1), name, cdict)]
|
self.formattree(inspect.getclasstree(classlist, 1), name)]
|
||||||
for key, value in classes:
|
for key, value in classes:
|
||||||
contents.append(self.document(value, key, name, fdict, cdict))
|
contents.append(self.document(value, key, name, fdict, cdict))
|
||||||
result = result + self.bigsection(
|
result = result + self.bigsection(
|
||||||
|
@ -558,8 +559,7 @@ TT { font-family: lucida console, lucida typewriter, courier }
|
||||||
if bases:
|
if bases:
|
||||||
parents = []
|
parents = []
|
||||||
for base in bases:
|
for base in bases:
|
||||||
parents.append(
|
parents.append(self.classlink(base, object.__module__))
|
||||||
self.classlink(base, object.__module__, classes))
|
|
||||||
title = title + '(%s)' % join(parents, ', ')
|
title = title + '(%s)' % join(parents, ', ')
|
||||||
doc = self.markup(
|
doc = self.markup(
|
||||||
getdoc(object), self.preformat, funcs, classes, mdict)
|
getdoc(object), self.preformat, funcs, classes, mdict)
|
||||||
|
@ -583,16 +583,14 @@ TT { font-family: lucida console, lucida typewriter, courier }
|
||||||
imclass = object.im_class
|
imclass = object.im_class
|
||||||
if cl:
|
if cl:
|
||||||
if imclass is not cl:
|
if imclass is not cl:
|
||||||
url = '%s.html#%s-%s' % (
|
note = ' from ' + self.classlink(imclass, mod)
|
||||||
imclass.__module__, imclass.__name__, name)
|
|
||||||
note = ' from <a href="%s">%s</a>' % (
|
|
||||||
url, classname(imclass, mod))
|
|
||||||
skipdocs = 1
|
skipdocs = 1
|
||||||
else:
|
else:
|
||||||
inst = object.im_self
|
if object.im_self:
|
||||||
note = (inst and
|
note = ' method of %s instance' % self.classlink(
|
||||||
' method of %s instance' % classname(inst.__class__, mod) or
|
object.im_self.__class__, mod)
|
||||||
' unbound %s method' % classname(imclass, mod))
|
else:
|
||||||
|
note = ' unbound %s method' % self.classlink(imclass,mod)
|
||||||
object = object.im_func
|
object = object.im_func
|
||||||
|
|
||||||
if name == realname:
|
if name == realname:
|
||||||
|
@ -848,10 +846,11 @@ class TextDoc(Doc):
|
||||||
note = ' from ' + classname(imclass, mod)
|
note = ' from ' + classname(imclass, mod)
|
||||||
skipdocs = 1
|
skipdocs = 1
|
||||||
else:
|
else:
|
||||||
inst = object.im_self
|
if object.im_self:
|
||||||
note = (inst and
|
note = ' method of %s instance' % classname(
|
||||||
' method of %s instance' % classname(inst.__class__, mod) or
|
object.im_self.__class__, mod)
|
||||||
' unbound %s method' % classname(imclass, mod))
|
else:
|
||||||
|
note = ' unbound %s method' % classname(imclass,mod)
|
||||||
object = object.im_func
|
object = object.im_func
|
||||||
|
|
||||||
if name == realname:
|
if name == realname:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue