Skip to content

Commit 1498675

Browse files
Fix linterstats.get_module_message_count() (#9146) (#9648)
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com> (cherry picked from commit d7526e3) Co-authored-by: zasca <gorstav@gmail.com>
1 parent aed496a commit 1498675

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

doc/whatsnew/fragments/9145.bugfix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Restore "errors / warnings by module" section to report output (with `-ry`).
2+
3+
Closes #9145

pylint/lint/report_functions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
import collections
88
from collections import defaultdict
9+
from typing import cast
910

1011
from pylint import checkers, exceptions
1112
from pylint.reporters.ureports.nodes import Section, Table
13+
from pylint.typing import MessageTypesFullName
1214
from pylint.utils import LinterStats
1315

1416

@@ -54,6 +56,7 @@ def report_messages_by_module_stats(
5456
raise exceptions.EmptyReportError()
5557
by_mod: defaultdict[str, dict[str, int | float]] = collections.defaultdict(dict)
5658
for m_type in ("fatal", "error", "warning", "refactor", "convention"):
59+
m_type = cast(MessageTypesFullName, m_type)
5760
total = stats.get_global_message_count(m_type)
5861
for module in module_stats.keys():
5962
mod_total = stats.get_module_message_count(module, m_type)

pylint/utils/linterstats.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,11 @@ def get_global_message_count(self, type_name: str) -> int:
292292
"""Get a global message count."""
293293
return getattr(self, type_name, 0)
294294

295-
def get_module_message_count(self, modname: str, type_name: str) -> int:
295+
def get_module_message_count(
296+
self, modname: str, type_name: MessageTypesFullName
297+
) -> int:
296298
"""Get a module message count."""
297-
return getattr(self.by_module[modname], type_name, 0)
299+
return self.by_module[modname].get(type_name, 0)
298300

299301
def increase_single_message_count(self, type_name: str, increase: int) -> None:
300302
"""Increase the message type count of an individual message type."""

tests/test_self.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,11 @@ def test_can_list_directories_without_dunder_init(tmp_path: Path) -> None:
988988
stderr=subprocess.PIPE,
989989
)
990990

991+
def test_warnings_by_module(self) -> None:
992+
path = join(HERE, "regrtest_data", "unused_variable.py")
993+
expected = "errors / warnings by module"
994+
self._test_output([path, "-ry"], expected_output=expected)
995+
991996
@pytest.mark.needs_two_cores
992997
def test_jobs_score(self) -> None:
993998
path = join(HERE, "regrtest_data", "unused_variable.py")

0 commit comments

Comments
 (0)