Skip to content

Prevent stats loss #9082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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