Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4c17c8

Browse files
committed
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...
1 parent e9fba91 commit b4c17c8

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Lib/inspect.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,14 @@ def findsource(object):
416416
raise IOError, 'could not find code object'
417417

418418
def getcomments(object):
419-
"""Get lines of comments immediately preceding an object's source code."""
420-
try: lines, lnum = findsource(object)
421-
except IOError: return None
419+
"""Get lines of comments immediately preceding an object's source code.
420+
421+
Returns None when source can't be found.
422+
"""
423+
try:
424+
lines, lnum = findsource(object)
425+
except (IOError, TypeError):
426+
return None
422427

423428
if ismodule(object):
424429
# Look for a comment block at the top of the file.

0 commit comments

Comments
 (0)