summaryrefslogtreecommitdiff
path: root/pylint/checkers/__init__.py
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-09-15 20:42:22 +0200
committerGitHub <noreply@github.com>2021-09-15 20:42:22 +0200
commit22e56c07cf745d695df1d52fe3988cc071f0951b (patch)
tree713b888a2f24239932b7d8a6a1d9f8bffe0026cd /pylint/checkers/__init__.py
parentcb896128b0e8f62c0650e980ef77a3c8af21ef8d (diff)
downloadpylint-git-22e56c07cf745d695df1d52fe3988cc071f0951b.tar.gz
Add typing to all calls to ``self.stats`` (#4973)
* Add typing to all calls to ``self.stats`` All checkers inherit from a baseclass which has a ``stats`` attribute. This attribute has a fairly unmanageable type, but the current typing includes all variations of the attribute. Other changes not directly related to ``self.stats`` are due to ``mypy``warnings. This incorporate the feedback received in #4954 * Add ``CheckerStatistic`` class to ``pylint/typing`` * Guard `typing.Counter` import Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Diffstat (limited to 'pylint/checkers/__init__.py')
-rw-r--r--pylint/checkers/__init__.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/pylint/checkers/__init__.py b/pylint/checkers/__init__.py
index ffc940223..584f476fc 100644
--- a/pylint/checkers/__init__.py
+++ b/pylint/checkers/__init__.py
@@ -46,28 +46,35 @@ messages nor reports. XXX not true, emit a 07 report !
"""
+from typing import Iterable, List, Union
+
from pylint.checkers.base_checker import BaseChecker, BaseTokenChecker
from pylint.checkers.deprecated import DeprecatedMixin
from pylint.checkers.mapreduce_checker import MapReduceMixin
+from pylint.typing import CheckerStats
from pylint.utils import diff_string, register_plugins
-def table_lines_from_stats(stats, old_stats, columns):
+def table_lines_from_stats(
+ stats: CheckerStats,
+ old_stats: CheckerStats,
+ columns: Iterable[str],
+) -> List[str]:
"""get values listed in <columns> from <stats> and <old_stats>,
and return a formated list of values, designed to be given to a
ureport.Table object
"""
- lines = []
+ lines: List[str] = []
for m_type in columns:
- new = stats[m_type]
- old = old_stats.get(m_type)
+ new: Union[int, str] = stats[m_type] # type: ignore
+ old: Union[int, str, None] = old_stats.get(m_type) # type: ignore
if old is not None:
diff_str = diff_string(old, new)
else:
old, diff_str = "NC", "NC"
new = f"{new:.3f}" if isinstance(new, float) else str(new)
old = f"{old:.3f}" if isinstance(old, float) else str(old)
- lines += (m_type.replace("_", " "), new, old, diff_str)
+ lines.extend((m_type.replace("_", " "), new, old, diff_str))
return lines