From 0a5da654286a4deee9094a27c8a4ccc1f5068613 Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Thu, 23 Oct 2025 20:00:10 -0700 Subject: [PATCH 1/3] regression test for #15979 https://github.com/python/mypy/pull/16019, which fixed this issue (for linux) was not accompanied by a regression test --- test-data/unit/reports.test | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test-data/unit/reports.test b/test-data/unit/reports.test index 82c3869bb855..231b953abe54 100644 --- a/test-data/unit/reports.test +++ b/test-data/unit/reports.test @@ -547,3 +547,10 @@ namespace_packages = True + +[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 From 78bf798bcebd0dbcb9065b93c03d1cbf28b7c15c Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Thu, 23 Oct 2025 20:28:22 -0700 Subject: [PATCH 2/3] Fix for Windows --- mypy/report.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mypy/report.py b/mypy/report.py index 39cd80ed38bf..35cbc34569ff 100644 --- a/mypy/report.py +++ b/mypy/report.py @@ -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() From 165bf3823c50759c1faa18f47226ab69da6221c1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 24 Oct 2025 03:39:15 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/report.py b/mypy/report.py index 35cbc34569ff..650fd538604e 100644 --- a/mypy/report.py +++ b/mypy/report.py @@ -172,7 +172,7 @@ 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). - if not os.path.isdir(tree.path): # can happen with namespace packages + if not os.path.isdir(tree.path): # can happen with namespace packages with open(tree.path, "rb") as f: physical_lines = len(f.readlines()) else: