Merge pull request #11996 from bluetech/getstatementrange-index-error
code: fix `IndexError` crash in `getstatementrange_ast`
This commit is contained in:
commit
aebeb33137
|
@ -0,0 +1 @@
|
||||||
|
Fix an ``IndexError`` crash raising from ``getstatementrange_ast``.
|
|
@ -197,7 +197,9 @@ def getstatementrange_ast(
|
||||||
# by using the BlockFinder helper used which inspect.getsource() uses itself.
|
# by using the BlockFinder helper used which inspect.getsource() uses itself.
|
||||||
block_finder = inspect.BlockFinder()
|
block_finder = inspect.BlockFinder()
|
||||||
# If we start with an indented line, put blockfinder to "started" mode.
|
# If we start with an indented line, put blockfinder to "started" mode.
|
||||||
block_finder.started = source.lines[start][0].isspace()
|
block_finder.started = (
|
||||||
|
bool(source.lines[start]) and source.lines[start][0].isspace()
|
||||||
|
)
|
||||||
it = ((x + "\n") for x in source.lines[start:end])
|
it = ((x + "\n") for x in source.lines[start:end])
|
||||||
try:
|
try:
|
||||||
for tok in tokenize.generate_tokens(lambda: next(it)):
|
for tok in tokenize.generate_tokens(lambda: next(it)):
|
||||||
|
|
Loading…
Reference in New Issue