Skip to content

Commit 097fb05

Browse files
Don't run checkers just for their reports when all messages are disabled (#10878)
Previously, prepare_checkers() would include a checker if any of its reports were enabled, even when all its messages were disabled. This meant checkers like `similarities` would still run their expensive computations (e.g. O(n²) duplicate-code detection) just to populate a report the user didn't ask for. Now, enabled reports only cause a checker to be included if it defines no messages at all (i.e. pure report-only checkers like RawMetrics). Closes #3443 Co-authored-by: Claude Opus 4.6 <[email protected]>
1 parent 5429be1 commit 097fb05

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The duplicate-code checker no longer runs when its message (R0801) is disabled, even if ``reports=yes`` is set. Previously, the checker's report (RP0801) would cause the expensive similarity computation to run regardless.
2+
3+
Closes #3443

pylint/lint/pylinter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,10 @@ def prepare_checkers(self) -> list[BaseChecker]:
617617
needed_checkers: list[BaseChecker] = [self]
618618
for checker in self.get_checkers()[1:]:
619619
messages = {msg for msg in checker.msgs if self.is_message_enabled(msg)}
620-
if messages or any(self.report_is_enabled(r[0]) for r in checker.reports):
620+
if messages or (
621+
not checker.msgs
622+
and any(self.report_is_enabled(r[0]) for r in checker.reports)
623+
):
621624
needed_checkers.append(checker)
622625
return needed_checkers
623626

tests/lint/unittest_lint.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,20 @@ def test_disable_similar(initialized_linter: PyLinter) -> None:
445445
assert "similarities" not in [c.name for c in linter.prepare_checkers()]
446446

447447

448+
def test_disable_similar_with_reports(initialized_linter: PyLinter) -> None:
449+
"""Disabling R0801 should exclude the similarities checker even with reports enabled.
450+
451+
Regression test for https://github.com/pylint-dev/pylint/issues/3443
452+
"""
453+
linter = initialized_linter
454+
linter.set_option("reports", True)
455+
linter.set_option("disable", "R0801")
456+
checker_names = [c.name for c in linter.prepare_checkers()]
457+
assert "similarities" not in checker_names
458+
# Report-only checkers (no messages) should still be included
459+
assert "metrics" in checker_names
460+
461+
448462
def test_disable_alot(linter: PyLinter) -> None:
449463
"""Check that we disabled a lot of checkers."""
450464
linter.set_option("reports", False)

0 commit comments

Comments
 (0)