mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	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).
This commit is contained in:
		
							parent
							
								
									39cd603fc8
								
							
						
					
					
						commit
						c86f6ca2b6
					
				
					 1 changed files with 22 additions and 1 deletions
				
			
		
							
								
								
									
										23
									
								
								Lib/pydoc.py
									
										
									
									
									
								
							
							
						
						
									
										23
									
								
								Lib/pydoc.py
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -624,6 +624,16 @@ TT { font-family: lucidatypewriter, lucida console, courier }
 | 
			
		|||
                self.needone = 1
 | 
			
		||||
        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)
 | 
			
		||||
            if ok:
 | 
			
		||||
| 
						 | 
				
			
			@ -738,6 +748,7 @@ TT { font-family: lucidatypewriter, lucida console, courier }
 | 
			
		|||
            title = title + '(%s)' % join(parents, ', ')
 | 
			
		||||
        doc = self.markup(getdoc(object), self.preformat, funcs, classes, mdict)
 | 
			
		||||
        doc = doc and '<tt>%s<br> </tt>' % doc or ' '
 | 
			
		||||
 | 
			
		||||
        return self.section(title, '#000000', '#ffc8d8', contents, 5, doc)
 | 
			
		||||
 | 
			
		||||
    def formatvalue(self, object):
 | 
			
		||||
| 
						 | 
				
			
			@ -985,12 +996,14 @@ class TextDoc(Doc):
 | 
			
		|||
        name = name or realname
 | 
			
		||||
        bases = object.__bases__
 | 
			
		||||
 | 
			
		||||
        def makename(c, m=object.__module__):
 | 
			
		||||
            return classname(c, m)
 | 
			
		||||
 | 
			
		||||
        if name == realname:
 | 
			
		||||
            title = 'class ' + self.bold(realname)
 | 
			
		||||
        else:
 | 
			
		||||
            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, ', ')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -998,6 +1011,14 @@ class TextDoc(Doc):
 | 
			
		|||
        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.
 | 
			
		||||
        class HorizontalRule:
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue