From b7a48300cd653964c82ae34eae9fab9bebef3578 Mon Sep 17 00:00:00 2001 From: Ka-Ping Yee Date: Thu, 12 Apr 2001 20:39:14 +0000 Subject: [PATCH] Fix linking to classes (in class tree, and add links on unbound methods). --- Lib/pydoc.py | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index ae421b1e71f..5f4cc1c65d0 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -342,12 +342,13 @@ TT { font-family: lucida console, lucida typewriter, courier } return '%s' % (dict[name], name) return name - def classlink(self, object, modname, *dicts): + def classlink(self, object, modname): """Make a link for a class.""" name = classname(object, modname) - for dict in dicts: - if dict.has_key(object): - return '%s' % (dict[object], name) + if sys.modules.has_key(object.__module__) and \ + getattr(sys.modules[object.__module__], object.__name__) is object: + return '%s' % ( + object.__module__, object.__name__, name) return name def modulelink(self, object): @@ -405,23 +406,23 @@ TT { font-family: lucida console, lucida typewriter, courier } # ---------------------------------------------- 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().""" result = '' for entry in tree: if type(entry) is type(()): c, bases = entry result = result + '
' - result = result + self.classlink(c, modname, classes) + result = result + self.classlink(c, modname) if bases and bases != (parent,): parents = [] for base in bases: - parents.append(self.classlink(base, modname, classes)) + parents.append(self.classlink(base, modname)) result = result + '(' + join(parents, ', ') + ')' result = result + '\n
' elif type(entry) is type([]): result = result + '
\n%s
\n' % self.formattree( - entry, modname, classes, c) + entry, modname, c) return '
\n%s
\n' % result def docmodule(self, object, name=None, mod=None): @@ -505,8 +506,8 @@ TT { font-family: lucida console, lucida typewriter, courier } if classes: classlist = map(lambda (key, value): value, classes) - contents = [self.formattree( - inspect.getclasstree(classlist, 1), name, cdict)] + contents = [ + self.formattree(inspect.getclasstree(classlist, 1), name)] for key, value in classes: contents.append(self.document(value, key, name, fdict, cdict)) result = result + self.bigsection( @@ -558,8 +559,7 @@ TT { font-family: lucida console, lucida typewriter, courier } if bases: parents = [] for base in bases: - parents.append( - self.classlink(base, object.__module__, classes)) + parents.append(self.classlink(base, object.__module__)) title = title + '(%s)' % join(parents, ', ') doc = self.markup( getdoc(object), self.preformat, funcs, classes, mdict) @@ -583,16 +583,14 @@ TT { font-family: lucida console, lucida typewriter, courier } imclass = object.im_class if cl: if imclass is not cl: - url = '%s.html#%s-%s' % ( - imclass.__module__, imclass.__name__, name) - note = ' from %s' % ( - url, classname(imclass, mod)) + note = ' from ' + self.classlink(imclass, mod) skipdocs = 1 else: - inst = object.im_self - note = (inst and - ' method of %s instance' % classname(inst.__class__, mod) or - ' unbound %s method' % classname(imclass, mod)) + if object.im_self: + note = ' method of %s instance' % self.classlink( + object.im_self.__class__, mod) + else: + note = ' unbound %s method' % self.classlink(imclass,mod) object = object.im_func if name == realname: @@ -848,10 +846,11 @@ class TextDoc(Doc): note = ' from ' + classname(imclass, mod) skipdocs = 1 else: - inst = object.im_self - note = (inst and - ' method of %s instance' % classname(inst.__class__, mod) or - ' unbound %s method' % classname(imclass, mod)) + if object.im_self: + note = ' method of %s instance' % classname( + object.im_self.__class__, mod) + else: + note = ' unbound %s method' % classname(imclass,mod) object = object.im_func if name == realname: