From 8de645a1760b953118eebbd9869f696509c74920 Mon Sep 17 00:00:00 2001 From: Johannes Gijsbers Date: Sun, 7 Nov 2004 19:16:05 +0000 Subject: [PATCH] Patch #1061931 / bug #971872: factor out part of spillproperties, so properties are also documented if help(Class.) is called instead of help(Class). --- Lib/pydoc.py | 85 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 30 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index daec8ab8191..3ae1c13fe89 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -298,6 +298,7 @@ class Doc: 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 @@ class HTMLDoc(Doc): hr.maybe() push(msg) for name, kind, homecls, value in ok: - push('
%s
\n' % name) - if value.__doc__ is not None: - doc = self.markup(value.__doc__, self.preformat, - funcs, classes, mdict) - push('
%s
\n' % doc) - for attr, tag in [('fget', 'get'), - ('fset', 'set'), - ('fdel', 'delete')]: - func = getattr(value, attr) - if func is not None: - base = self.document(func, tag, mod, - funcs, classes, mdict, object) - push('
%s
\n' % base) - push('
\n') + push(self._docproperty(name, value, mod)) return attrs def spilldata(msg, attrs, predicate): @@ -884,6 +872,30 @@ class HTMLDoc(Doc): doc = doc and '
%s
' % doc return '
%s
%s
\n' % (decl, doc) + def _docproperty(self, name, value, mod): + results = [] + push = results.append + + if name: + push('
%s
\n' % name) + if value.__doc__ is not None: + doc = self.markup(value.__doc__, self.preformat) + push('
%s
\n' % doc) + for attr, tag in [('fget', 'get'), + ('fset', 'set'), + ('fdel', 'delete')]: + func = getattr(value, attr) + if func is not None: + base = self.document(func, tag, mod) + push('
%s
\n' % base) + push('
\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 '%s = ' % name or '' @@ -1138,22 +1150,7 @@ class TextDoc(Doc): 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', ''), - ('fset', ''), - ('fdel', '')]: - 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 @@ class TextDoc(Doc): 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', ''), + ('fset', ''), + ('fdel', '')]: + 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)