From f0cc482312a393935a762c6b1b1e2aa8d7508b5b Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 27 Jul 2016 10:46:10 -0700 Subject: [PATCH] Quick fix for --linecount-report if a file contains non-ASCII text. --- mypy/report.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mypy/report.py b/mypy/report.py index f50678159cd4..180bbe610bad 100644 --- a/mypy/report.py +++ b/mypy/report.py @@ -76,7 +76,9 @@ def __init__(self, reports: Reports, output_dir: str) -> None: stats.ensure_dir_exists(output_dir) def on_file(self, tree: MypyFile, type_map: Dict[Node, Type]) -> None: - physical_lines = len(open(tree.path).readlines()) + # Count physical lines. This assumes the file's encoding is a + # superset of ASCII (or at least uses \n in its line endings). + physical_lines = len(open(tree.path, 'rb').readlines()) func_counter = FuncCounterVisitor() tree.accept(func_counter)