summaryrefslogtreecommitdiff
path: root/pylint/utils
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-11-08 09:06:51 +0100
committerGitHub <noreply@github.com>2021-11-08 09:06:51 +0100
commitc6fcd01f268243b891cec96c19a6fc93595f4e17 (patch)
treea7ab8840c35e118c09f464b45b92a93926dd6106 /pylint/utils
parent6827dfe84e793a4fc9a07afc3a463ded6e22b230 (diff)
downloadpylint-git-c6fcd01f268243b891cec96c19a6fc93595f4e17.tar.gz
Create and use a function for module stats initialization (#5271)
This permit to reduce the coupling between Pylinter and linterstats. Also add two missing litteral in typing for module stats and independant typing for ModuleStats attribute Refactor prior to #4720
Diffstat (limited to 'pylint/utils')
-rw-r--r--pylint/utils/linterstats.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/pylint/utils/linterstats.py b/pylint/utils/linterstats.py
index f46054455..cb2085352 100644
--- a/pylint/utils/linterstats.py
+++ b/pylint/utils/linterstats.py
@@ -73,6 +73,11 @@ class ModuleStats(TypedDict):
warning: int
+ModuleStatsAttribute = Literal[
+ "convention", "error", "fatal", "info", "refactor", "statement", "warning"
+]
+
+
# pylint: disable-next=too-many-instance-attributes
class LinterStats:
"""Class used to linter stats"""
@@ -149,6 +154,12 @@ class LinterStats:
{self.nb_duplicated_lines}
{self.percent_duplicated_lines}"""
+ def init_single_module(self, module_name: str) -> None:
+ """Use through Pylinter.set_current_module so Pyliner.current_name is consistent."""
+ 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[
@@ -279,15 +290,10 @@ class LinterStats:
setattr(self, type_name, getattr(self, type_name) + increase)
def increase_single_module_message_count(
- self,
- modname: str,
- type_name: Literal["convention", "error", "fatal", "info", "refactor"],
- increase: int,
+ self, modname: str, type_name: ModuleStatsAttribute, 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"""