import_cache: make sure last line ends with \n as linecache does. Closes #547

pull/584/head
Sebastien Bourdeauducq 2016-09-02 11:01:28 +08:00
parent dbc08bde8a
commit c414026b29
1 changed files with 4 additions and 1 deletions

View File

@ -29,7 +29,10 @@ def hook_exec_module(self, module):
fn = module.__file__
try:
with tokenize.open(fn) as fp:
cache[fn] = fp.readlines()
lines = fp.readlines()
if lines and not lines[-1].endswith("\n"):
lines[-1] += "\n"
cache[fn] = lines
except:
logger.warning("failed to add '%s' to cache", fn, exc_info=True)
else: