diff options
-rw-r--r-- | pylint/constants.py | 6 | ||||
-rw-r--r-- | pylint/lint/pylinter.py | 10 | ||||
-rw-r--r-- | pylint/typing.py | 6 | ||||
-rw-r--r-- | pylint/utils/file_state.py | 4 | ||||
-rw-r--r-- | pylint/utils/linterstats.py | 9 |
5 files changed, 24 insertions, 11 deletions
diff --git a/pylint/constants.py b/pylint/constants.py index db54113ee..813cd54dd 100644 --- a/pylint/constants.py +++ b/pylint/constants.py @@ -2,11 +2,13 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE import platform import sys +from typing import Dict import astroid import platformdirs from pylint.__pkginfo__ import __version__ +from pylint.typing import MessageTypesFullName PY37_PLUS = sys.version_info[:2] >= (3, 7) PY38_PLUS = sys.version_info[:2] >= (3, 8) @@ -24,7 +26,7 @@ MSG_STATE_SCOPE_MODULE = 1 # The line/node distinction does not apply to fatal errors and reports. _SCOPE_EXEMPT = "FR" -MSG_TYPES = { +MSG_TYPES: Dict[str, MessageTypesFullName] = { "I": "info", "C": "convention", "R": "refactor", @@ -32,7 +34,7 @@ MSG_TYPES = { "E": "error", "F": "fatal", } -MSG_TYPES_LONG = {v: k for k, v in MSG_TYPES.items()} +MSG_TYPES_LONG: Dict[str, str] = {v: k for k, v in MSG_TYPES.items()} MSG_TYPES_STATUS = {"I": 0, "C": 16, "R": 8, "W": 4, "E": 2, "F": 1} diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py index 379fefe04..f1954e371 100644 --- a/pylint/lint/pylinter.py +++ b/pylint/lint/pylinter.py @@ -546,7 +546,7 @@ class PyLinter( def __init__( self, options=(), - reporter=None, + reporter: Union[reporters.BaseReporter, reporters.MultiReporter, None] = None, option_groups=(), pylintrc=None, ): @@ -1552,7 +1552,11 @@ class PyLinter( msg_cat = MSG_TYPES[message_definition.msgid[0]] self.msg_status |= MSG_TYPES_STATUS[message_definition.msgid[0]] self.stats.increase_single_message_count(msg_cat, 1) - self.stats.increase_single_module_message_count(self.current_name, msg_cat, 1) + self.stats.increase_single_module_message_count( + self.current_name, # type: ignore[arg-type] # Should be removable after https://github.com/PyCQA/pylint/pull/5580 + msg_cat, + 1, + ) try: self.stats.by_msg[message_definition.symbol] += 1 except KeyError: @@ -1669,6 +1673,8 @@ class PyLinter( ) -> None: """Set the status of an individual message""" if scope == "module": + assert isinstance(line, int) # should always be int inside module scope + self.file_state.set_msg_status(msg, line, enable) if not enable and msg.symbol != "locally-disabled": self.add_message( diff --git a/pylint/typing.py b/pylint/typing.py index 402a6f716..09e4df126 100644 --- a/pylint/typing.py +++ b/pylint/typing.py @@ -64,3 +64,9 @@ class ManagedMessage(NamedTuple): symbol: str line: Optional[int] is_disabled: bool + + +MessageTypesFullName = Literal[ + "convention", "error", "fatal", "info", "refactor", "statement", "warning" +] +"""All possible message categories.""" diff --git a/pylint/utils/file_state.py b/pylint/utils/file_state.py index 8527031ea..4252f0154 100644 --- a/pylint/utils/file_state.py +++ b/pylint/utils/file_state.py @@ -130,7 +130,7 @@ class FileState: self._module_msgs_state[msg.msgid] = {line: status} def handle_ignored_message( - self, state_scope: Optional[Literal[0, 1, 2]], msgid: str, line: int + self, state_scope: Optional[Literal[0, 1, 2]], msgid: str, line: Optional[int] ) -> None: """Report an ignored message. @@ -139,6 +139,8 @@ class FileState: or globally. """ if state_scope == MSG_STATE_SCOPE_MODULE: + assert isinstance(line, int) # should always be int inside module scope + try: orig_line = self._suppression_mapping[(msgid, line)] self._ignored_msgs[(msgid, orig_line)].add(line) diff --git a/pylint/utils/linterstats.py b/pylint/utils/linterstats.py index 4a05c93df..125954e4e 100644 --- a/pylint/utils/linterstats.py +++ b/pylint/utils/linterstats.py @@ -4,6 +4,8 @@ import sys from typing import Dict, List, Optional, Set, cast +from pylint.typing import MessageTypesFullName + if sys.version_info >= (3, 8): from typing import Literal, TypedDict else: @@ -73,11 +75,6 @@ class ModuleStats(TypedDict): warning: int -ModuleStatsAttribute = Literal[ - "convention", "error", "fatal", "info", "refactor", "statement", "warning" -] - - # pylint: disable-next=too-many-instance-attributes class LinterStats: """Class used to linter stats""" @@ -290,7 +287,7 @@ class LinterStats: setattr(self, type_name, getattr(self, type_name) + increase) def increase_single_module_message_count( - self, modname: str, type_name: ModuleStatsAttribute, increase: int + self, modname: str, type_name: MessageTypesFullName, increase: int ) -> None: """Increase the message type count of an individual message type of a module""" self.by_module[modname][type_name] += increase |