From 8b976154f649ea033910b2ac6a30b38cb4af4ed8 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 13 Dec 2016 02:25:03 -0800 Subject: [PATCH] [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 --- infer/lib/python/inferlib/source.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infer/lib/python/inferlib/source.py b/infer/lib/python/inferlib/source.py index 7eb57bf78..682bf33d9 100644 --- a/infer/lib/python/inferlib/source.py +++ b/infer/lib/python/inferlib/source.py @@ -75,7 +75,7 @@ def build_source_context(source_name, mode, report_line): # avoid going past the end of the file for line in source_file: last_line = line_number - if start_line <= line_number < end_line: + if start_line <= line_number <= end_line: excerpt += line elif line_number > end_line: # 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)) s = '' 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), colorize.DIM, mode) caret = ' '