From 0dfa3d39f1ce845e16772870e433f98204470c26 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 2 Sep 2023 00:18:07 -0700 Subject: [PATCH] Fix crash with report generation on namespace packages (again) --- mypy/report.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mypy/report.py b/mypy/report.py index 5d93351aa37da..8be0cbec94f24 100644 --- a/mypy/report.py +++ b/mypy/report.py @@ -171,8 +171,12 @@ def on_file( ) -> None: # Count physical lines. This assumes the file's encoding is a # superset of ASCII (or at least uses \n in its line endings). - with open(tree.path, "rb") as f: - physical_lines = len(f.readlines()) + try: + with open(tree.path, "rb") as f: + physical_lines = len(f.readlines()) + except IsADirectoryError: + # can happen with namespace packages + physical_lines = 0 func_counter = FuncCounterVisitor() tree.accept(func_counter)