Skip to content

Commit 29bf25c

Browse files
authored
Add types to option attributes of PyLinter and reorganize init (#5579)
1 parent 45b5e7b commit 29bf25c

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

pylint/lint/pylinter.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Optional,
2222
Sequence,
2323
Set,
24+
Tuple,
2425
Type,
2526
Union,
2627
)
@@ -72,6 +73,8 @@
7273
else:
7374
from typing_extensions import Literal
7475

76+
OptionDict = Dict[str, Union[str, bool, int, Iterable[Union[str, int]]]]
77+
7578
MANAGER = astroid.MANAGER
7679

7780

@@ -216,7 +219,7 @@ class PyLinter(
216219
crash_file_path: str = "pylint-crash-%Y-%m-%d-%H.txt"
217220

218221
@staticmethod
219-
def make_options():
222+
def make_options() -> Tuple[Tuple[str, OptionDict], ...]:
220223
return (
221224
(
222225
"ignore",
@@ -526,7 +529,7 @@ def make_options():
526529
),
527530
)
528531

529-
option_groups = (
532+
base_option_groups = (
530533
("Messages control", "Options controlling analysis messages"),
531534
("Reports", "Options related to output formatting and reporting"),
532535
)
@@ -557,21 +560,26 @@ def __init__(
557560
self._dynamic_plugins: Set[str] = set()
558561
"""Set of loaded plugin names"""
559562

560-
self.msgs_store = MessageDefinitionStore()
561-
self._pragma_lineno = {}
562-
563563
# Attributes related to visiting files
564564
self.file_state = FileState()
565565
self.current_name: Optional[str] = None
566566
self.current_file: Optional[str] = None
567567
self._ignore_file = False
568+
self._pragma_lineno: Dict[str, int] = {}
568569

570+
# Attributes related to stats
569571
self.stats = LinterStats()
570-
self.fail_on_symbols = []
571-
# init options
572-
self._external_opts = options
573-
self.options = options + PyLinter.make_options()
574-
self.option_groups = option_groups + PyLinter.option_groups
572+
573+
# Attributes related to (command-line) options and their parsing
574+
# pylint: disable-next=fixme
575+
# TODO: Make these implicitly typing when typing for __init__ parameter is added
576+
self._external_opts: Tuple[Tuple[str, OptionDict], ...] = options
577+
self.options: Tuple[Tuple[str, OptionDict], ...] = (
578+
options + PyLinter.make_options()
579+
)
580+
self.option_groups: Tuple[Tuple[str, str], ...] = (
581+
option_groups + PyLinter.base_option_groups
582+
)
575583
self._options_methods = {
576584
"enable": self.enable,
577585
"disable": self.disable,
@@ -581,8 +589,12 @@ def __init__(
581589
"disable-msg": self._options_methods["disable"],
582590
"enable-msg": self._options_methods["enable"],
583591
}
592+
self.fail_on_symbols: List[str] = []
593+
"""List of message symbols on which pylint should fail, set by --fail-on"""
594+
self._error_mode = False
584595

585-
# Attributes related to message (state) handling
596+
# Attributes related to messages (states) and their handling
597+
self.msgs_store = MessageDefinitionStore()
586598
self.msg_status = 0
587599
self._msgs_state: Dict[str, bool] = {}
588600
self._by_id_managed_msgs: List[ManagedMessage] = []
@@ -604,7 +616,6 @@ def __init__(
604616
("RP0003", "Messages", report_messages_stats),
605617
)
606618
self.register_checker(self)
607-
self._error_mode = False
608619
self.load_provider_defaults()
609620

610621
def load_default_plugins(self):

0 commit comments

Comments
 (0)