We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
IndexError
getstatementrange_ast
1 parent 9844781 commit 9f13d41Copy full SHA for 9f13d41
changelog/11953.bugfix.rst
@@ -0,0 +1 @@
1
+Fix an ``IndexError`` crash raising from ``getstatementrange_ast``.
src/_pytest/_code/source.py
@@ -197,7 +197,9 @@ def getstatementrange_ast(
197
# by using the BlockFinder helper used which inspect.getsource() uses itself.
198
block_finder = inspect.BlockFinder()
199
# If we start with an indented line, put blockfinder to "started" mode.
200
- block_finder.started = source.lines[start][0].isspace()
+ block_finder.started = (
201
+ bool(source.lines[start]) and source.lines[start][0].isspace()
202
+ )
203
it = ((x + "\n") for x in source.lines[start:end])
204
try:
205
for tok in tokenize.generate_tokens(lambda: next(it)):
0 commit comments