From fb86ac70f5ca4c19d39bf219c9dcd1499db2c281 Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Mon, 16 Aug 2021 10:32:40 +0100 Subject: [PATCH] Comment Match.__str__ and use format() to simplify calculation Signed-off-by: Yuto Takano --- tests/scripts/check_names.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/scripts/check_names.py b/tests/scripts/check_names.py index 591389b960..5dc38fc523 100755 --- a/tests/scripts/check_names.py +++ b/tests/scripts/check_names.py @@ -77,15 +77,16 @@ class Match(): # pylint: disable=too-few-public-methods self.name = name def __str__(self): - ln_str = str(self.pos[0]) - gutter_len = max(4, len(ln_str)) - gutter = (gutter_len - len(ln_str)) * " " + ln_str + """ + Return a formatted code listing representation of the erroneous line. + """ + gutter = format(self.pos[0], "4d") underline = self.pos[1] * " " + (self.pos[2] - self.pos[1]) * "^" return ( - " {0} |\n".format(gutter_len * " ") + + " {0} |\n".format(" " * len(gutter)) + " {0} | {1}".format(gutter, self.line) + - " {0} | {1}\n".format(gutter_len * " ", underline) + " {0} | {1}\n".format(" " * len(gutter), underline) ) class Problem(): # pylint: disable=too-few-public-methods