Skip to content

Commit 797d99b

Browse files
authored
Add typing to checker and plugin attributes of PyLinter (#5574)
1 parent d98cef7 commit 797d99b

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

pylint/lint/pylinter.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@
1111
import traceback
1212
import warnings
1313
from io import TextIOWrapper
14-
from typing import Any, Dict, Iterable, Iterator, List, Optional, Sequence, Type, Union
14+
from typing import (
15+
Any,
16+
DefaultDict,
17+
Dict,
18+
Iterable,
19+
Iterator,
20+
List,
21+
Optional,
22+
Sequence,
23+
Set,
24+
Type,
25+
Union,
26+
)
1527

1628
import astroid
1729
from astroid import AstroidError, nodes
@@ -537,8 +549,15 @@ def __init__(
537549
self._reporters: Dict[str, Type[reporters.BaseReporter]] = {}
538550
"""Dictionary of possible but non-initialized reporters"""
539551

552+
# Attributes for checkers and plugins
553+
self._checkers: DefaultDict[
554+
str, List[checkers.BaseChecker]
555+
] = collections.defaultdict(list)
556+
"""Dictionary of registered and initialized checkers"""
557+
self._dynamic_plugins: Set[str] = set()
558+
"""Set of loaded plugin names"""
559+
540560
self.msgs_store = MessageDefinitionStore()
541-
self._checkers = collections.defaultdict(list)
542561
self._pragma_lineno = {}
543562

544563
# Attributes related to visiting files
@@ -585,7 +604,6 @@ def __init__(
585604
("RP0003", "Messages", report_messages_stats),
586605
)
587606
self.register_checker(self)
588-
self._dynamic_plugins = set()
589607
self._error_mode = False
590608
self.load_provider_defaults()
591609

@@ -722,7 +740,7 @@ def report_order(self):
722740

723741
# checkers manipulation methods ############################################
724742

725-
def register_checker(self, checker):
743+
def register_checker(self, checker: checkers.BaseChecker) -> None:
726744
"""register a new checker
727745
728746
checker is an object implementing IRawChecker or / and IAstroidChecker

pylint/reporters/reports_handler_mix_in.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
import collections
55
from typing import TYPE_CHECKING, Callable, DefaultDict, Dict, List, Optional, Tuple
66

7+
from pylint import checkers
78
from pylint.exceptions import EmptyReportError
8-
from pylint.interfaces import IChecker
99
from pylint.reporters.ureports.nodes import Section
1010
from pylint.utils import LinterStats
1111

1212
if TYPE_CHECKING:
1313
from pylint.lint.pylinter import PyLinter
1414

15-
ReportsDict = DefaultDict[IChecker, List[Tuple[str, str, Callable]]]
15+
ReportsDict = DefaultDict[checkers.BaseChecker, List[Tuple[str, str, Callable]]]
1616

1717

1818
class ReportsHandlerMixIn:
@@ -24,12 +24,12 @@ def __init__(self) -> None:
2424
self._reports: ReportsDict = collections.defaultdict(list)
2525
self._reports_state: Dict[str, bool] = {}
2626

27-
def report_order(self) -> List[IChecker]:
27+
def report_order(self) -> List[checkers.BaseChecker]:
2828
"""Return a list of reporters"""
2929
return list(self._reports)
3030

3131
def register_report(
32-
self, reportid: str, r_title: str, r_cb: Callable, checker: IChecker
32+
self, reportid: str, r_title: str, r_cb: Callable, checker: checkers.BaseChecker
3333
) -> None:
3434
"""register a report
3535

0 commit comments

Comments
 (0)