]> granicus.if.org Git - python/commitdiff
Have pydoc try handling an object as "other" if the object does not act the way
authorBrett Cannon <bcannon@gmail.com>
Wed, 11 Jun 2003 23:38:55 +0000 (23:38 +0000)
committerBrett Cannon <bcannon@gmail.com>
Wed, 11 Jun 2003 23:38:55 +0000 (23:38 +0000)
it expects based on what inspect classifies it as.

Closes bug #729103 .

Lib/pydoc.py

index a6778d6ac204c07941b07debb943442bafb45ee2..fe114fd78286e6467318d39ebc0a189e01a9a33b 100755 (executable)
@@ -275,9 +275,16 @@ class Doc:
     def document(self, object, name=None, *args):
         """Generate documentation for an object."""
         args = (object, name) + args
-        if inspect.ismodule(object): return self.docmodule(*args)
-        if inspect.isclass(object): return self.docclass(*args)
-        if inspect.isroutine(object): return self.docroutine(*args)
+        # 'try' clause is to attempt to handle the possibility that inspect
+        # identifies something in a way that pydoc itself has issues handling;
+        # think 'super' and how it is a descriptor (which raises the exception
+        # by lacking a __name__ attribute) and an instance.
+        try:
+            if inspect.ismodule(object): return self.docmodule(*args)
+            if inspect.isclass(object): return self.docclass(*args)
+            if inspect.isroutine(object): return self.docroutine(*args)
+        except AttributeError:
+            pass
         return self.docother(*args)
 
     def fail(self, object, name=None, *args):