summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2002-03-28 23:01:56 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2002-03-28 23:01:56 (GMT)
commitb4c17c899284eae9923495c0879af8aa0e91dfd6 (patch)
treed162fa072e143ed2c8e5ec4a1313774d1815aea1 /Lib
parente9fba9188ea1b9674a6a262774dc9abf1221d24e (diff)
downloadcpython-b4c17c899284eae9923495c0879af8aa0e91dfd6.zip
cpython-b4c17c899284eae9923495c0879af8aa0e91dfd6.tar.gz
cpython-b4c17c899284eae9923495c0879af8aa0e91dfd6.tar.bz2
Fix getcomments() so that it doesn't fail with TypeErrors.
It appears that getcomments() can get called for classes defined in C. Since these don't have source code, it can't do anything useful. A function buried many levels deep was raising a TypeError that was not caught. Who knows why this broke...
Diffstat (limited to 'Lib')
-rw-r--r--Lib/inspect.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 175f5d6..2b28d8e 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -416,9 +416,14 @@ def findsource(object):
raise IOError, 'could not find code object'
def getcomments(object):
- """Get lines of comments immediately preceding an object's source code."""
- try: lines, lnum = findsource(object)
- except IOError: return None
+ """Get lines of comments immediately preceding an object's source code.
+
+ Returns None when source can't be found.
+ """
+ try:
+ lines, lnum = findsource(object)
+ except (IOError, TypeError):
+ return None
if ismodule(object):
# Look for a comment block at the top of the file.