Skip to content

Commit

Permalink
Prevent stats loss (#9082)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored Oct 1, 2023
1 parent ca8690a commit 9c69801
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions doc/whatsnew/fragments/9059.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Prevented data loss in the linter stats for messages relating
to the linter itself (e.g. ``unknown-option-value``), fixing
problems with score, fail-on, etc.

Closes #9059
1 change: 0 additions & 1 deletion pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,6 @@ def _check_astroid_module(

def open(self) -> None:
"""Initialize counters."""
self.stats = LinterStats()
MANAGER.always_load_extensions = self.config.unsafe_load_any_extension
MANAGER.max_inferable_values = self.config.limit_inference_results
MANAGER.extension_package_whitelist.update(self.config.extension_pkg_allow_list)
Expand Down
9 changes: 8 additions & 1 deletion tests/lint/unittest_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@
from pylint.testutils import create_files
from pylint.testutils._run import _Run as Run
from pylint.typing import MessageLocationTuple
from pylint.utils import FileState, print_full_documentation, tokenize_module
from pylint.utils import (
FileState,
LinterStats,
print_full_documentation,
tokenize_module,
)

if os.name == "java":
if os.name == "nt":
Expand Down Expand Up @@ -1030,6 +1035,8 @@ def test_by_module_statement_value(initialized_linter: PyLinter) -> None:
by_module_stats = linter.stats.by_module
for module, module_stats in by_module_stats.items():
linter2 = initialized_linter
linter2.stats = LinterStats()

if module == "data":
linter2.check([os.path.join(os.path.dirname(__file__), "data/__init__.py")])
else:
Expand Down
1 change: 1 addition & 0 deletions tests/test_check_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ def test_sequential_checkers_work(self) -> None:
# now run the regular mode of checking files and check that, in this proc, we
# collect the right data
filepath = [single_file_container[0][1]] # get the filepath element
linter.stats = LinterStats()
linter.check(filepath)
assert {
"input.similar1": { # module is the only change from previous
Expand Down
2 changes: 2 additions & 0 deletions tests/test_regr.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from pylint import testutils
from pylint.lint.pylinter import PyLinter
from pylint.utils.linterstats import LinterStats

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

os.chdir(join(REGR_DATA, "package"))
finalize_linter.stats = LinterStats()
finalize_linter.check(["__init__"])
checked = list(finalize_linter.stats.by_module.keys())
assert checked == ["__init__"]
Expand Down
9 changes: 9 additions & 0 deletions tests/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,15 @@ def test_fail_on(self, fu_score: int, fo_msgs: str, fname: str, out: int) -> Non
(["--disable=C0116", "--fail-on=C0116"], 16),
# Ensure order does not matter
(["--fail-on=C0116", "--disable=C0116"], 16),
# Message emitted by PyLinter itself
(
[
"--fail-on=unknown-option-value",
"--disable=all",
"--enable=unknown-option-value, trigger",
],
4,
),
],
)
def test_fail_on_edge_case(self, opts: list[str], out: int) -> None:
Expand Down

0 comments on commit 9c69801

Please sign in to comment.