diff options
author | Ka-Ping Yee <ping@zesty.ca> | 2001-04-12 13:17:17 (GMT) |
---|---|---|
committer | Ka-Ping Yee <ping@zesty.ca> | 2001-04-12 13:17:17 (GMT) |
commit | b910efe8a948acc7a39d91ca7cfff96f0968a580 (patch) | |
tree | 2ab856bc7b2c1eefc51cda2f20870dadbe301e67 | |
parent | fd540695e7830ad93695410104b8a2ca934993cf (diff) | |
download | cpython-b910efe8a948acc7a39d91ca7cfff96f0968a580.zip cpython-b910efe8a948acc7a39d91ca7cfff96f0968a580.tar.gz cpython-b910efe8a948acc7a39d91ca7cfff96f0968a580.tar.bz2 |
Robustify getcomments() so it doesn't crash on empty files.
-rw-r--r-- | Lib/inspect.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 140dbd1..b1f723d 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -305,10 +305,10 @@ def getcomments(object): if ismodule(object): # Look for a comment block at the top of the file. start = 0 - if lines[0][:2] == '#!': start = 1 + if lines and lines[0][:2] == '#!': start = 1 while start < len(lines) and string.strip(lines[start]) in ['', '#']: start = start + 1 - if lines[start][:1] == '#': + if start < len(lines) and lines[start][:1] == '#': comments = [] end = start while end < len(lines) and lines[end][:1] == '#': |