Skip to content

Commit

Permalink
Fix bug: ast_from_source should not modify linecache inplace
Browse files Browse the repository at this point in the history
  • Loading branch information
hsfzxjy committed Feb 20, 2021
1 parent 61685b3 commit b3a1bd3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lambdex/utils/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def ast_from_source(source, keyword: str):
if first_keyword_loc >= 0: break
lnum -= 1

lines[lnum] = lines[lnum][first_keyword_loc:]
lines = [lines[lnum][first_keyword_loc:]] + lines[lnum + 1:]
# Prepend the lines with newlines, so that parsed AST will have correct lineno
source_lines = ['\n'] * lnum + inspect.getblock(lines[lnum:])
source_lines = ['\n'] * lnum + inspect.getblock(lines)
source = ''.join(source_lines)

# Some garbage may still remain at the end, we alternatively try compiling
Expand Down

0 comments on commit b3a1bd3

Please sign in to comment.