From 0b70762c825e548e013331fc1ae20ba5258f2b5b Mon Sep 17 00:00:00 2001 From: Svyatoslav Ilinskiy Date: Fri, 26 May 2017 11:37:34 -0700 Subject: [PATCH 1/3] Fix last character cut in html-report if file does not end with newline If a file did not end with a newline, html-report would not output it. --- mypy/report.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mypy/report.py b/mypy/report.py index 74b44ac1f995..632d5aee591e 100644 --- a/mypy/report.py +++ b/mypy/report.py @@ -331,10 +331,12 @@ def on_file(self, for lineno, line_text in enumerate(input_file, 1): status = visitor.line_map.get(lineno, stats.TYPE_EMPTY) file_info.counts[status] += 1 + if line_text.endswith('\n'): + line_text = line_text[:-1] etree.SubElement(root, 'line', number=str(lineno), precision=stats.precision_names[status], - content=line_text[:-1]) + content=line_text) # Assumes a layout similar to what XmlReporter uses. xslt_path = os.path.relpath('mypy-html.xslt', path) transform_pi = etree.ProcessingInstruction('xml-stylesheet', From 03cf727cf59526402d4764484e469dc9bfa2ea85 Mon Sep 17 00:00:00 2001 From: Svyatoslav Ilinskiy Date: Fri, 26 May 2017 11:52:50 -0700 Subject: [PATCH 2/3] Use strip() instead of checking the last character --- mypy/report.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mypy/report.py b/mypy/report.py index 632d5aee591e..76ebc2a47f4c 100644 --- a/mypy/report.py +++ b/mypy/report.py @@ -331,12 +331,10 @@ def on_file(self, for lineno, line_text in enumerate(input_file, 1): status = visitor.line_map.get(lineno, stats.TYPE_EMPTY) file_info.counts[status] += 1 - if line_text.endswith('\n'): - line_text = line_text[:-1] etree.SubElement(root, 'line', number=str(lineno), precision=stats.precision_names[status], - content=line_text) + content=line_text.strip('\n')) # Assumes a layout similar to what XmlReporter uses. xslt_path = os.path.relpath('mypy-html.xslt', path) transform_pi = etree.ProcessingInstruction('xml-stylesheet', From 9048c98427a7f962b91dee67e1c00dcea6589b65 Mon Sep 17 00:00:00 2001 From: Svyatoslav Ilinskiy Date: Fri, 26 May 2017 11:58:15 -0700 Subject: [PATCH 3/3] Use rstrip() instead of strip() --- mypy/report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/report.py b/mypy/report.py index 76ebc2a47f4c..157aa1caab6f 100644 --- a/mypy/report.py +++ b/mypy/report.py @@ -334,7 +334,7 @@ def on_file(self, etree.SubElement(root, 'line', number=str(lineno), precision=stats.precision_names[status], - content=line_text.strip('\n')) + content=line_text.rstrip('\n')) # Assumes a layout similar to what XmlReporter uses. xslt_path = os.path.relpath('mypy-html.xslt', path) transform_pi = etree.ProcessingInstruction('xml-stylesheet',