summaryrefslogtreecommitdiff
path: root/pylint/utils
diff options
context:
space:
mode:
authorDaniël van Noord <13665637+DanielNoord@users.noreply.github.com>2021-10-01 11:15:44 +0200
committerDaniël van Noord <13665637+DanielNoord@users.noreply.github.com>2021-10-01 11:42:13 +0200
commita655e78fa8e9c51c6455806c1f04ef3f839c0526 (patch)
treecf5805dd5fdb3be63f5596a384d6a92fc0dcb382 /pylint/utils
parent8c74530e677ad2e8332f5ab0e7e64516571aae40 (diff)
downloadpylint-git-a655e78fa8e9c51c6455806c1f04ef3f839c0526.tar.gz
Move ``merge_stats`` to ``checkerstats.py``
Diffstat (limited to 'pylint/utils')
-rw-r--r--pylint/utils/__init__.py2
-rw-r--r--pylint/utils/checkerstats.py30
2 files changed, 32 insertions, 0 deletions
diff --git a/pylint/utils/__init__.py b/pylint/utils/__init__.py
index 77cb08b76..a0658bf99 100644
--- a/pylint/utils/__init__.py
+++ b/pylint/utils/__init__.py
@@ -44,6 +44,7 @@ main pylint class
"""
from pylint.utils.ast_walker import ASTWalker
+from pylint.utils.checkerstats import merge_stats
from pylint.utils.file_state import FileState
from pylint.utils.utils import (
HAS_ISORT_5,
@@ -83,4 +84,5 @@ __all__ = [
"normalize_text",
"register_plugins",
"tokenize_module",
+ "merge_stats",
]
diff --git a/pylint/utils/checkerstats.py b/pylint/utils/checkerstats.py
new file mode 100644
index 000000000..42af08167
--- /dev/null
+++ b/pylint/utils/checkerstats.py
@@ -0,0 +1,30 @@
+# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
+
+import collections
+from typing import TYPE_CHECKING, Dict, List, Union
+
+from pylint.typing import CheckerStats
+
+if TYPE_CHECKING:
+ from typing import Counter # typing.Counter added in Python 3.6.1
+
+
+def merge_stats(stats: List[CheckerStats]):
+ """Used to merge two stats objects into a new one when pylint is run in parallel mode"""
+ merged: CheckerStats = {}
+ by_msg: "Counter[str]" = collections.Counter()
+ for stat in stats:
+ message_stats: Union["Counter[str]", Dict] = stat.pop("by_msg", {}) # type: ignore
+ by_msg.update(message_stats)
+
+ for key, item in stat.items():
+ if key not in merged:
+ merged[key] = item
+ elif isinstance(item, dict):
+ merged[key].update(item) # type: ignore
+ else:
+ merged[key] = merged[key] + item # type: ignore
+
+ merged["by_msg"] = by_msg
+ return merged