summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-11-07 15:13:05 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-11-07 23:30:46 +0100
commitafcbe6db58c0925d8c4ef77f142077aed68e7083 (patch)
tree672998699cedc5b7e0f4fa1fd8c302e40af66e45
parent6827dfe84e793a4fc9a07afc3a463ded6e22b230 (diff)
downloadpylint-git-afcbe6db58c0925d8c4ef77f142077aed68e7083.tar.gz
Create and use a function for module stats initialization
This permit to reduce the coupling between Pylinter and linterstats. Refactor prior to #4720
-rw-r--r--pylint/lint/pylinter.py14
-rw-r--r--pylint/utils/linterstats.py10
2 files changed, 9 insertions, 15 deletions
diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py
index 4c9756696..7f4005070 100644
--- a/pylint/lint/pylinter.py
+++ b/pylint/lint/pylinter.py
@@ -46,14 +46,7 @@ from pylint.typing import (
MessageLocationTuple,
ModuleDescriptionDict,
)
-from pylint.utils import (
- ASTWalker,
- FileState,
- LinterStats,
- ModuleStats,
- get_global_option,
- utils,
-)
+from pylint.utils import ASTWalker, FileState, LinterStats, get_global_option, utils
from pylint.utils.pragma_parser import (
OPTION_PO,
InvalidPragmaError,
@@ -1125,9 +1118,7 @@ class PyLinter(
self.reporter.on_set_current_module(modname, filepath)
self.current_name = modname
self.current_file = filepath or modname
- self.stats.by_module[modname] = ModuleStats(
- convention=0, error=0, fatal=0, info=0, refactor=0, statement=0, warning=0
- )
+ self.stats.init_single_module(modname)
@contextlib.contextmanager
def _astroid_module_checker(self):
@@ -1435,7 +1426,6 @@ class PyLinter(
# update stats
msg_cat = MSG_TYPES[message_definition.msgid[0]]
self.msg_status |= MSG_TYPES_STATUS[message_definition.msgid[0]]
-
self.stats.increase_single_message_count(msg_cat, 1)
self.stats.increase_single_module_message_count(self.current_name, msg_cat, 1)
try:
diff --git a/pylint/utils/linterstats.py b/pylint/utils/linterstats.py
index f46054455..18a5b5052 100644
--- a/pylint/utils/linterstats.py
+++ b/pylint/utils/linterstats.py
@@ -149,6 +149,12 @@ class LinterStats:
{self.nb_duplicated_lines}
{self.percent_duplicated_lines}"""
+ def init_single_module(self, module_name: str) -> None:
+ """Initialize module statistics if required."""
+ self.by_module[module_name] = ModuleStats(
+ convention=0, error=0, fatal=0, info=0, refactor=0, statement=0, warning=0
+ )
+
def get_bad_names(
self,
node_name: Literal[
@@ -285,9 +291,7 @@ class LinterStats:
increase: int,
) -> None:
"""Increase the message type count of an individual message type of a module"""
- self.by_module[modname][type_name] = (
- self.by_module[modname][type_name] + increase
- )
+ self.by_module[modname][type_name] += increase
def reset_message_count(self) -> None:
"""Resets the message type count of the stats object"""