summaryrefslogtreecommitdiff
path: root/pylint/reporters
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-12-27 21:30:34 +0100
committerGitHub <noreply@github.com>2021-12-27 21:30:34 +0100
commit7d2584251552283bf95893019e74dad0390dc65c (patch)
tree7b5b8fa573a94d73b97741789a3e1fe35c7e7824 /pylint/reporters
parent691b41b3ddd3b533bce4d6a1f03ebc1e5cacf508 (diff)
downloadpylint-git-7d2584251552283bf95893019e74dad0390dc65c.tar.gz
Add typing and uniformize the checker registering in Pylinter (#5558)
Remove verbose docstring in code, keep them in example and doc Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Diffstat (limited to 'pylint/reporters')
-rw-r--r--pylint/reporters/json_reporter.py1
-rw-r--r--pylint/reporters/reports_handler_mix_in.py41
-rw-r--r--pylint/reporters/text.py1
3 files changed, 24 insertions, 19 deletions
diff --git a/pylint/reporters/json_reporter.py b/pylint/reporters/json_reporter.py
index 84d11d24a..8761979aa 100644
--- a/pylint/reporters/json_reporter.py
+++ b/pylint/reporters/json_reporter.py
@@ -59,5 +59,4 @@ class JSONReporter(BaseReporter):
def register(linter: "PyLinter") -> None:
- """Register the reporter classes with the linter."""
linter.register_reporter(JSONReporter)
diff --git a/pylint/reporters/reports_handler_mix_in.py b/pylint/reporters/reports_handler_mix_in.py
index a71e1bc7b..245d2ded1 100644
--- a/pylint/reporters/reports_handler_mix_in.py
+++ b/pylint/reporters/reports_handler_mix_in.py
@@ -2,21 +2,30 @@
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
import collections
-from typing import TYPE_CHECKING, Callable, DefaultDict, Dict, List, Optional, Tuple
+from typing import (
+ TYPE_CHECKING,
+ Callable,
+ DefaultDict,
+ Dict,
+ List,
+ MutableSequence,
+ Optional,
+ Tuple,
+)
-from pylint import checkers
from pylint.exceptions import EmptyReportError
from pylint.reporters.ureports.nodes import Section
from pylint.utils import LinterStats
if TYPE_CHECKING:
+ from pylint.checkers import BaseChecker
from pylint.lint.pylinter import PyLinter
-ReportsDict = DefaultDict[checkers.BaseChecker, List[Tuple[str, str, Callable]]]
+ReportsDict = DefaultDict["BaseChecker", List[Tuple[str, str, Callable]]]
class ReportsHandlerMixIn:
- """a mix-in class containing all the reports and stats manipulation
+ """A mix-in class containing all the reports and stats manipulation
related methods for the main lint class
"""
@@ -24,37 +33,35 @@ class ReportsHandlerMixIn:
self._reports: ReportsDict = collections.defaultdict(list)
self._reports_state: Dict[str, bool] = {}
- def report_order(self) -> List[checkers.BaseChecker]:
+ def report_order(self) -> MutableSequence["BaseChecker"]:
"""Return a list of reporters"""
return list(self._reports)
def register_report(
- self, reportid: str, r_title: str, r_cb: Callable, checker: checkers.BaseChecker
+ self, reportid: str, r_title: str, r_cb: Callable, checker: "BaseChecker"
) -> None:
- """register a report
+ """Register a report
- reportid is the unique identifier for the report
- r_title the report's title
- r_cb the method to call to make the report
- checker is the checker defining the report
+ :param reportid: The unique identifier for the report
+ :param r_title: The report's title
+ :param r_cb: The method to call to make the report
+ :param checker: The checker defining the report
"""
reportid = reportid.upper()
self._reports[checker].append((reportid, r_title, r_cb))
def enable_report(self, reportid: str) -> None:
- """disable the report of the given id"""
+ """Enable the report of the given id"""
reportid = reportid.upper()
self._reports_state[reportid] = True
def disable_report(self, reportid: str) -> None:
- """disable the report of the given id"""
+ """Disable the report of the given id"""
reportid = reportid.upper()
self._reports_state[reportid] = False
def report_is_enabled(self, reportid: str) -> bool:
- """return true if the report associated to the given identifier is
- enabled
- """
+ """Is the report associated to the given identifier enabled ?"""
return self._reports_state.get(reportid, True)
def make_reports( # type: ignore[misc] # ReportsHandlerMixIn is always mixed with PyLinter
@@ -62,7 +69,7 @@ class ReportsHandlerMixIn:
stats: LinterStats,
old_stats: Optional[LinterStats],
) -> Section:
- """render registered reports"""
+ """Render registered reports"""
sect = Section("Report", f"{self.stats.statement} statements analysed.")
for checker in self.report_order():
for reportid, r_title, r_cb in self._reports[checker]:
diff --git a/pylint/reporters/text.py b/pylint/reporters/text.py
index 7b6e5e1a1..b69a3a139 100644
--- a/pylint/reporters/text.py
+++ b/pylint/reporters/text.py
@@ -352,7 +352,6 @@ class ColorizedTextReporter(TextReporter):
def register(linter: "PyLinter") -> None:
- """Register the reporter classes with the linter."""
linter.register_reporter(TextReporter)
linter.register_reporter(ParseableTextReporter)
linter.register_reporter(VSTextReporter)