]> granicus.if.org Git - python/commitdiff
Handle old-style instances more gracefully (display documentation on
authorKa-Ping Yee <ping@zesty.ca>
Sun, 14 Jan 2007 04:25:15 +0000 (04:25 +0000)
committerKa-Ping Yee <ping@zesty.ca>
Sun, 14 Jan 2007 04:25:15 +0000 (04:25 +0000)
the relevant class instead of documentation on <type 'instance'>).

Lib/pydoc.py

index ce9751787b8fcb2452a33197a59041fd4a27f592..94927d02706939996dcc2566e758fb627e54a1aa 100755 (executable)
@@ -1448,6 +1448,9 @@ def locate(path, forceload=0):
 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 @@ def doc(thing, title='Python Library Documentation: %s', forceload=0):
             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)