Mailing List Archive

CVS: python/dist/src/Lib inspect.py,1.30,1.31
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv25488

Modified Files:
inspect.py
Log Message:
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...


Index: inspect.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/inspect.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** inspect.py 25 Mar 2002 21:37:54 -0000 1.30
--- inspect.py 28 Mar 2002 23:01:56 -0000 1.31
***************
*** 417,423 ****

def getcomments(object):
! """Get lines of comments immediately preceding an object's source code."""
! try: lines, lnum = findsource(object)
! except IOError: return None

if ismodule(object):
--- 417,428 ----

def getcomments(object):
! """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):