Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions mypy/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,10 @@ 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).
try:
if not os.path.isdir(tree.path): # can happen with namespace packages
with open(tree.path, "rb") as f:
physical_lines = len(f.readlines())
except IsADirectoryError:
# can happen with namespace packages
else:
physical_lines = 0

func_counter = FuncCounterVisitor()
Expand Down
7 changes: 7 additions & 0 deletions test-data/unit/reports.test
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,10 @@ namespace_packages = True
</table>
</body>
</html>

[case testLinecountReportCrashOnNamespacePackages]
# cmd: mypy --linecount-report report -p folder
--Regression test for https://github.com/python/mypy/issues/15979
[file folder/subfolder/something.py]
class Something:
pass