Skip to content

Commit

Permalink
Fix crash with report generation on namespace packages (again) (#16019)
Browse files Browse the repository at this point in the history
Fixes #15979. Fix is similar to that in `iterate_python_lines`.
  • Loading branch information
hauntsaninja authored Sep 2, 2023
1 parent 1655b0c commit 5adf934
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mypy/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5adf934

Please sign in to comment.