diff --git a/mypy/report.py b/mypy/report.py index 5d93351aa37d..8be0cbec94f2 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)