mirror of
https://github.com/python/cpython.git
synced 2025-12-01 07:19:24 +00:00
Robustify getcomments() so it doesn't crash on empty files.
This commit is contained in:
parent
fd540695e7
commit
b910efe8a9
1 changed files with 2 additions and 2 deletions
|
|
@ -305,10 +305,10 @@ def getcomments(object):
|
||||||
if ismodule(object):
|
if ismodule(object):
|
||||||
# Look for a comment block at the top of the file.
|
# Look for a comment block at the top of the file.
|
||||||
start = 0
|
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 ['', '#']:
|
while start < len(lines) and string.strip(lines[start]) in ['', '#']:
|
||||||
start = start + 1
|
start = start + 1
|
||||||
if lines[start][:1] == '#':
|
if start < len(lines) and lines[start][:1] == '#':
|
||||||
comments = []
|
comments = []
|
||||||
end = start
|
end = start
|
||||||
while end < len(lines) and lines[end][:1] == '#':
|
while end < len(lines) and lines[end][:1] == '#':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue