Fix another problem in inspect: if the module for an object cannot be found, don't try to give its __dict__ to linecache.

This commit is contained in:
Georg Brandl 2006-04-30 17:42:26 +00:00
parent 72ae6c80d4
commit 208badda27
1 changed files with 5 additions and 1 deletions

View File

@ -412,7 +412,11 @@ def findsource(object):
in the file and the line number indexes a line in that list. An IOError
is raised if the source code cannot be retrieved."""
file = getsourcefile(object) or getfile(object)
lines = linecache.getlines(file, getmodule(object).__dict__)
module = getmodule(object)
if module:
lines = linecache.getlines(file, module.__dict__)
else:
lines = linecache.getlines(file)
if not lines:
raise IOError('could not get source code')