Skip to content

Commit 9c69801

Browse files
Prevent stats loss (#9082)
1 parent ca8690a commit 9c69801

File tree

6 files changed

+25
-2
lines changed

6 files changed

+25
-2
lines changed

doc/whatsnew/fragments/9059.bugfix

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Prevented data loss in the linter stats for messages relating
2+
to the linter itself (e.g. ``unknown-option-value``), fixing
3+
problems with score, fail-on, etc.
4+
5+
Closes #9059

pylint/lint/pylinter.py

-1
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,6 @@ def _check_astroid_module(
10711071

10721072
def open(self) -> None:
10731073
"""Initialize counters."""
1074-
self.stats = LinterStats()
10751074
MANAGER.always_load_extensions = self.config.unsafe_load_any_extension
10761075
MANAGER.max_inferable_values = self.config.limit_inference_results
10771076
MANAGER.extension_package_whitelist.update(self.config.extension_pkg_allow_list)

tests/lint/unittest_lint.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@
4141
from pylint.testutils import create_files
4242
from pylint.testutils._run import _Run as Run
4343
from pylint.typing import MessageLocationTuple
44-
from pylint.utils import FileState, print_full_documentation, tokenize_module
44+
from pylint.utils import (
45+
FileState,
46+
LinterStats,
47+
print_full_documentation,
48+
tokenize_module,
49+
)
4550

4651
if os.name == "java":
4752
if os.name == "nt":
@@ -1030,6 +1035,8 @@ def test_by_module_statement_value(initialized_linter: PyLinter) -> None:
10301035
by_module_stats = linter.stats.by_module
10311036
for module, module_stats in by_module_stats.items():
10321037
linter2 = initialized_linter
1038+
linter2.stats = LinterStats()
1039+
10331040
if module == "data":
10341041
linter2.check([os.path.join(os.path.dirname(__file__), "data/__init__.py")])
10351042
else:

tests/test_check_parallel.py

+1
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ def test_sequential_checkers_work(self) -> None:
382382
# now run the regular mode of checking files and check that, in this proc, we
383383
# collect the right data
384384
filepath = [single_file_container[0][1]] # get the filepath element
385+
linter.stats = LinterStats()
385386
linter.check(filepath)
386387
assert {
387388
"input.similar1": { # module is the only change from previous

tests/test_regr.py

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from pylint import testutils
2222
from pylint.lint.pylinter import PyLinter
23+
from pylint.utils.linterstats import LinterStats
2324

2425
REGR_DATA = join(dirname(abspath(__file__)), "regrtest_data")
2526
sys.path.insert(1, REGR_DATA)
@@ -116,6 +117,7 @@ def test_check_package___init__(finalize_linter: PyLinter) -> None:
116117
assert sorted(checked) == sorted(filename)
117118

118119
os.chdir(join(REGR_DATA, "package"))
120+
finalize_linter.stats = LinterStats()
119121
finalize_linter.check(["__init__"])
120122
checked = list(finalize_linter.stats.by_module.keys())
121123
assert checked == ["__init__"]

tests/test_self.py

+9
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,15 @@ def test_fail_on(self, fu_score: int, fo_msgs: str, fname: str, out: int) -> Non
768768
(["--disable=C0116", "--fail-on=C0116"], 16),
769769
# Ensure order does not matter
770770
(["--fail-on=C0116", "--disable=C0116"], 16),
771+
# Message emitted by PyLinter itself
772+
(
773+
[
774+
"--fail-on=unknown-option-value",
775+
"--disable=all",
776+
"--enable=unknown-option-value, trigger",
777+
],
778+
4,
779+
),
771780
],
772781
)
773782
def test_fail_on_edge_case(self, opts: list[str], out: int) -> None:

0 commit comments

Comments
 (0)