[Python-checkins] python/dist/src/Lib pydoc.py,1.98,1.99

jlgijsbers at users.sourceforge.net jlgijsbers at users.sourceforge.net
Sun Nov 7 20:16:09 CET 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32434

Modified Files:
	pydoc.py 
Log Message:
Patch #1061931 / bug #971872: factor out part of spillproperties, so
properties are also documented if help(Class.<property>) is called
instead of help(Class).


Index: pydoc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pydoc.py,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- pydoc.py	30 Aug 2004 14:13:04 -0000	1.98
+++ pydoc.py	7 Nov 2004 19:16:05 -0000	1.99
@@ -298,6 +298,7 @@
             if inspect.isroutine(object): return self.docroutine(*args)
         except AttributeError:
             pass
+        if isinstance(object, property): return self.docproperty(*args)
         return self.docother(*args)
 
     def fail(self, object, name=None, *args):
@@ -724,20 +725,7 @@
                 hr.maybe()
                 push(msg)
                 for name, kind, homecls, value in ok:
-                    push('<dl><dt><strong>%s</strong></dt>\n' % name)
-                    if value.__doc__ is not None:
-                        doc = self.markup(value.__doc__, self.preformat,
-                                          funcs, classes, mdict)
-                        push('<dd><tt>%s</tt></dd>\n' % doc)
-                    for attr, tag in [('fget', '<em>get</em>'),
-                                      ('fset', '<em>set</em>'),
-                                      ('fdel', '<em>delete</em>')]:
-                        func = getattr(value, attr)
-                        if func is not None:
-                            base = self.document(func, tag, mod,
-                                                 funcs, classes, mdict, object)
-                            push('<dd>%s</dd>\n' % base)
-                    push('</dl>\n')
+                    push(self._docproperty(name, value, mod))
             return attrs
 
         def spilldata(msg, attrs, predicate):
@@ -884,6 +872,30 @@
             doc = doc and '<dd><tt>%s</tt></dd>' % doc
             return '<dl><dt>%s</dt>%s</dl>\n' % (decl, doc)
 
+    def _docproperty(self, name, value, mod):
+        results = []
+        push = results.append
+
+        if name:
+            push('<dl><dt><strong>%s</strong></dt>\n' % name)
+        if value.__doc__ is not None:
+            doc = self.markup(value.__doc__, self.preformat)
+            push('<dd><tt>%s</tt></dd>\n' % doc)
+        for attr, tag in [('fget', '<em>get</em>'),
+                          ('fset', '<em>set</em>'),
+                          ('fdel', '<em>delete</em>')]:
+            func = getattr(value, attr)
+            if func is not None:
+                base = self.document(func, tag, mod)
+                push('<dd>%s</dd>\n' % base)
+        push('</dl>\n')
+
+        return ''.join(results)
+
+    def docproperty(self, object, name=None, mod=None, cl=None):
+        """Produce html documentation for a property."""
+        return self._docproperty(name, object, mod)
+
     def docother(self, object, name=None, mod=None, *ignored):
         """Produce HTML documentation for a data object."""
         lhs = name and '<strong>%s</strong> = ' % name or ''
@@ -1138,22 +1150,7 @@
                 hr.maybe()
                 push(msg)
                 for name, kind, homecls, value in ok:
-                    push(name)
-                    need_blank_after_doc = 0
-                    doc = getdoc(value) or ''
-                    if doc:
-                        push(self.indent(doc))
-                        need_blank_after_doc = 1
-                    for attr, tag in [('fget', '<get>'),
-                                      ('fset', '<set>'),
-                                      ('fdel', '<delete>')]:
-                        func = getattr(value, attr)
-                        if func is not None:
-                            if need_blank_after_doc:
-                                push('')
-                                need_blank_after_doc = 0
-                            base = self.document(func, tag, mod)
-                            push(self.indent(base))
+                    push(self._docproperty(name, value, mod))
             return attrs
 
         def spilldata(msg, attrs, predicate):
@@ -1258,6 +1255,34 @@
             doc = getdoc(object) or ''
             return decl + '\n' + (doc and rstrip(self.indent(doc)) + '\n')
 
+    def _docproperty(self, name, value, mod):
+        results = []
+        push = results.append
+
+        if name:
+            push(name)
+        need_blank_after_doc = 0
+        doc = getdoc(value) or ''
+        if doc:
+            push(self.indent(doc))
+            need_blank_after_doc = 1
+        for attr, tag in [('fget', '<get>'),
+                          ('fset', '<set>'),
+                          ('fdel', '<delete>')]:
+            func = getattr(value, attr)
+            if func is not None:
+                if need_blank_after_doc:
+                    push('')
+                    need_blank_after_doc = 0
+                base = self.document(func, tag, mod)
+                push(self.indent(base))
+
+        return '\n'.join(results)
+
+    def docproperty(self, object, name=None, mod=None, cl=None):
+        """Produce text documentation for a property."""
+        return self._docproperty(name, object, mod)
+
     def docother(self, object, name=None, mod=None, maxlen=None, doc=None):
         """Produce text documentation for a data object."""
         repr = self.repr(object)



More information about the Python-checkins mailing list