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

Tim Peters tim_one@users.sourceforge.net
Mon, 24 Sep 2001 15:40:49 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv18973/python/Lib

Modified Files:
	pydoc.py 
Log Message:
+ 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).


Index: pydoc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pydoc.py,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** pydoc.py	2001/09/24 08:05:11	1.46
--- pydoc.py	2001/09/24 22:40:47	1.47
***************
*** 992,998 ****
--- 992,1009 ----
          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:
***************
*** 1001,1013 ****
              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:
                  push(msg)
                  for name, kind, homecls, value in ok:
!                     push(name + '\n')
              return attrs
  
--- 1012,1038 ----
              return attrs
  
          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)
!                     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
  
***************
*** 1015,1018 ****
--- 1040,1044 ----
              ok, attrs = _split_list(attrs, predicate)
              if ok:
+                 hr.maybe()
                  push(msg)
                  for name, kind, homecls, value in ok:
***************
*** 1041,1053 ****
  
              # Pump out the attrs, segregated by kind.
!             attrs = spill("* Methods %s:\n" % tag, attrs,
                            lambda t: t[1] == 'method')
!             attrs = spill("* Class methods %s:\n" % tag, attrs,
                            lambda t: t[1] == 'class method')
!             attrs = spill("* Static methods %s:\n" % tag, attrs,
                            lambda t: t[1] == 'static method')
!             attrs = spillproperties("* Properties %s:\n" % tag, attrs,
                                      lambda t: t[1] == 'property')
!             attrs = spilldata("* Data %s:\n" % tag, attrs,
                                lambda t: t[1] == 'data')
              assert attrs == []
--- 1067,1079 ----
  
              # Pump out the attrs, segregated by kind.
!             attrs = spill("Methods %s:\n" % tag, attrs,
                            lambda t: t[1] == 'method')
!             attrs = spill("Class methods %s:\n" % tag, attrs,
                            lambda t: t[1] == 'class method')
!             attrs = spill("Static methods %s:\n" % tag, attrs,
                            lambda t: t[1] == 'static method')
!             attrs = spillproperties("Properties %s:\n" % tag, attrs,
                                      lambda t: t[1] == 'property')
!             attrs = spilldata("Data %s:\n" % tag, attrs,
                                lambda t: t[1] == 'data')
              assert attrs == []