[python] remove trailing empty line in source contexts

Summary: lines end in '\n' so the last item in `lines.split('\n')` is always empty.

Reviewed By: jeremydubreil

Differential Revision: D4299036

fbshipit-source-id: b3cacbf
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent 715f6ffa7e
commit 8b976154f6

@ -75,7 +75,7 @@ def build_source_context(source_name, mode, report_line):
# avoid going past the end of the file # avoid going past the end of the file
for line in source_file: for line in source_file:
last_line = line_number last_line = line_number
if start_line <= line_number < end_line: if start_line <= line_number <= end_line:
excerpt += line excerpt += line
elif line_number > end_line: elif line_number > end_line:
# OPTIM: no need to read past the last line of the excerpt # OPTIM: no need to read past the last line of the excerpt
@ -88,7 +88,7 @@ def build_source_context(source_name, mode, report_line):
n_length = len(str(last_line)) n_length = len(str(last_line))
s = '' s = ''
line_number = start_line line_number = start_line
for line in excerpt.split('\n'): for line in excerpt.split('\n')[:-1]:
num = colorize.color((str(line_number) + '.').zfill(n_length), num = colorize.color((str(line_number) + '.').zfill(n_length),
colorize.DIM, mode) colorize.DIM, mode)
caret = ' ' caret = ' '

Loading…
Cancel
Save