summaryrefslogtreecommitdiffstats
path: root/Lib/pydoc.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-24 22:40:47 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-09-24 22:40:47 (GMT)
commitf4aad8eb28606a7cfa0266a1f2c28c003e8cd36e (patch)
tree98efdfd327e87131957fb63a8e062d1c8533382e /Lib/pydoc.py
parent66c1a525e08fda439ddda3b6371236df1398cfd5 (diff)
downloadcpython-f4aad8eb28606a7cfa0266a1f2c28c003e8cd36e.zip
cpython-f4aad8eb28606a7cfa0266a1f2c28c003e8cd36e.tar.gz
cpython-f4aad8eb28606a7cfa0266a1f2c28c003e8cd36e.tar.bz2
+ Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
properties: the docstring (if any) is displayed, and the getter, setter and deleter (if any) functions are named. All that is shown indented after the property name. + Text-mode pydoc class display now draws a horizontal line between class attribute groups (similar to GUI mode -- while visually more intrusive in text mode, it's still an improvement).
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-xLib/pydoc.py44
1 files changed, 35 insertions, 9 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index a6f9fa9..4bf1940 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -991,29 +991,55 @@ class TextDoc(Doc):
contents = doc and [doc + '\n'] or []
push = contents.append
+ # Cute little class to pump out a horizontal rule between sections.
+ class HorizontalRule:
+ def __init__(self):
+ self.needone = 0
+ def maybe(self):
+ if self.needone:
+ push('-' * 70)
+ self.needone = 1
+ hr = HorizontalRule()
+
def spill(msg, attrs, predicate):
ok, attrs = _split_list(attrs, predicate)
if ok:
+ hr.maybe()
push(msg)
for name, kind, homecls, value in ok:
push(self.document(getattr(object, name),
name, mod, object))
return attrs
- # pydoc can't make any reasonable sense of properties on its own,
- # and it doesn't appear that the getter, setter and del'er methods
- # are discoverable. For now, just pump out their names.
def spillproperties(msg, attrs, predicate):
ok, attrs = _split_list(attrs, predicate)
if ok:
+ hr.maybe()
push(msg)
for name, kind, homecls, value in ok:
- push(name + '\n')
+ 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 [("fset", " setter"),
+ ("fget", " getter"),
+ ("fdel", " deleter")]:
+ func = getattr(value, attr)
+ if func is not None:
+ if need_blank_after_doc:
+ push('')
+ need_blank_after_doc = 0
+ base = self.docother(func, name + tag, mod, 70)
+ push(self.indent(base))
+ push('')
return attrs
def spilldata(msg, attrs, predicate):
ok, attrs = _split_list(attrs, predicate)
if ok:
+ hr.maybe()
push(msg)
for name, kind, homecls, value in ok:
doc = getattr(value, "__doc__", None)
@@ -1040,15 +1066,15 @@ class TextDoc(Doc):
attrs.sort(lambda t1, t2: cmp(t1[0], t2[0]))
# Pump out the attrs, segregated by kind.
- attrs = spill("* Methods %s:\n" % tag, attrs,
+ attrs = spill("Methods %s:\n" % tag, attrs,
lambda t: t[1] == 'method')
- attrs = spill("* Class methods %s:\n" % tag, attrs,
+ attrs = spill("Class methods %s:\n" % tag, attrs,
lambda t: t[1] == 'class method')
- attrs = spill("* Static methods %s:\n" % tag, attrs,
+ attrs = spill("Static methods %s:\n" % tag, attrs,
lambda t: t[1] == 'static method')
- attrs = spillproperties("* Properties %s:\n" % tag, attrs,
+ attrs = spillproperties("Properties %s:\n" % tag, attrs,
lambda t: t[1] == 'property')
- attrs = spilldata("* Data %s:\n" % tag, attrs,
+ attrs = spilldata("Data %s:\n" % tag, attrs,
lambda t: t[1] == 'data')
assert attrs == []