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

Skip to content

Commit b910efe

Browse files
committed
Robustify getcomments() so it doesn't crash on empty files.
1 parent fd54069 commit b910efe

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Lib/inspect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,10 @@ def getcomments(object):
305305
if ismodule(object):
306306
# Look for a comment block at the top of the file.
307307
start = 0
308-
if lines[0][:2] == '#!': start = 1
308+
if lines and lines[0][:2] == '#!': start = 1
309309
while start < len(lines) and string.strip(lines[start]) in ['', '#']:
310310
start = start + 1
311-
if lines[start][:1] == '#':
311+
if start < len(lines) and lines[start][:1] == '#':
312312
comments = []
313313
end = start
314314
while end < len(lines) and lines[end][:1] == '#':

0 commit comments

Comments
 (0)