[Python-checkins] CVS: python/dist/src/Lib pydoc.py,1.50,1.51

Tim Peters tim_one@users.sourceforge.net
2001年9月26日 14:31:53 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv10730/python/Lib
Modified Files:
	pydoc.py 
Log Message:
Display a class's method resolution order, if it's non-trivial. "Trivial"
here means it has no more than one base class to rummage through (in which
cases there's no potential confusion about resolution order).
Index: pydoc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pydoc.py,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -d -r1.50 -r1.51
*** pydoc.py	2001年09月25日 06:30:51	1.50
--- pydoc.py	2001年09月26日 21:31:51	1.51
***************
*** 625,628 ****
--- 625,638 ----
 hr = HorizontalRule()
 
+ # List the mro, if non-trivial.
+ mro = inspect.getmro(object)
+ if len(mro) > 2:
+ hr.maybe()
+ push('<dl><dt>Method resolution order:</dt>\n')
+ for base in mro:
+ push('<dd>%s</dd>\n' % self.classlink(base,
+ object.__module__))
+ push('</dl>\n')
+ 
 def spill(msg, attrs, predicate):
 ok, attrs = _split_list(attrs, predicate)
***************
*** 739,742 ****
--- 749,753 ----
 doc = self.markup(getdoc(object), self.preformat, funcs, classes, mdict)
 doc = doc and '<tt>%s<br>&nbsp;</tt>' % doc or '&nbsp;'
+ 
 return self.section(title, '#000000', '#ffc8d8', contents, 5, doc)
 
***************
*** 986,989 ****
--- 997,1003 ----
 bases = object.__bases__
 
+ def makename(c, m=object.__module__):
+ return classname(c, m)
+ 
 if name == realname:
 title = 'class ' + self.bold(realname)
***************
*** 991,995 ****
 title = self.bold(name) + ' = class ' + realname
 if bases:
- def makename(c, m=object.__module__): return classname(c, m)
 parents = map(makename, bases)
 title = title + '(%s)' % join(parents, ', ')
--- 1005,1008 ----
***************
*** 998,1001 ****
--- 1011,1022 ----
 contents = doc and [doc + '\n'] or []
 push = contents.append
+ 
+ # List the mro, if non-trivial.
+ mro = inspect.getmro(object)
+ if len(mro) > 2:
+ push("Method resolution order:")
+ for base in mro:
+ push(' ' + makename(base))
+ push('')
 
 # Cute little class to pump out a horizontal rule between sections.

AltStyle によって変換されたページ (->オリジナル) /