]> granicus.if.org Git - python/commitdiff
Robustify getcomments() so it doesn't crash on empty files.
authorKa-Ping Yee <ping@zesty.ca>
Thu, 12 Apr 2001 13:17:17 +0000 (13:17 +0000)
committerKa-Ping Yee <ping@zesty.ca>
Thu, 12 Apr 2001 13:17:17 +0000 (13:17 +0000)
Lib/inspect.py

index 140dbd12a8491760a22f8104233bca39277efa44..b1f723d1185147c59a8d3c113a8bdf6cf514b814 100644 (file)
@@ -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] == '#':