[Python-checkins] r53425 - python/trunk/Lib/pydoc.py

ka-ping.yee python-checkins at python.org
Sun Jan 14 05:25:16 CET 2007


Author: ka-ping.yee
Date: Sun Jan 14 05:25:15 2007
New Revision: 53425

Modified:
   python/trunk/Lib/pydoc.py
Log:
Handle old-style instances more gracefully (display documentation on
the relevant class instead of documentation on <type 'instance'>).


Modified: python/trunk/Lib/pydoc.py
==============================================================================
--- python/trunk/Lib/pydoc.py	(original)
+++ python/trunk/Lib/pydoc.py	Sun Jan 14 05:25:15 2007
@@ -1448,6 +1448,9 @@
 text = TextDoc()
 html = HTMLDoc()
 
+class _OldStyleClass: pass
+_OLD_INSTANCE_TYPE = type(_OldStyleClass())
+
 def resolve(thing, forceload=0):
     """Given an object or a path to an object, get the object and its name."""
     if isinstance(thing, str):
@@ -1468,12 +1471,16 @@
             desc += ' in ' + name[:name.rfind('.')]
         elif module and module is not object:
             desc += ' in module ' + module.__name__
-        if not (inspect.ismodule(object) or
-                inspect.isclass(object) or
-                inspect.isroutine(object) or
-                inspect.isgetsetdescriptor(object) or
-                inspect.ismemberdescriptor(object) or
-                isinstance(object, property)):
+        if type(object) is _OLD_INSTANCE_TYPE:
+            # If the passed object is an instance of an old-style class,
+            # document its available methods instead of its value.
+            object = object.__class__
+        elif not (inspect.ismodule(object) or
+                  inspect.isclass(object) or
+                  inspect.isroutine(object) or
+                  inspect.isgetsetdescriptor(object) or
+                  inspect.ismemberdescriptor(object) or
+                  isinstance(object, property)):
             # If the passed object is a piece of data or an instance,
             # document its available methods instead of its value.
             object = type(object)


More information about the Python-checkins mailing list