summaryrefslogtreecommitdiff
path: root/pylint/lint
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2023-03-08 22:09:38 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2023-03-08 23:44:58 +0100
commit03bfeff94692821f7f06e5c6bec42476358b289f (patch)
tree44fc753b1b8a811296110c36cc42d212367e3e7e /pylint/lint
parent44180da558453da6d1b2d8d8de7665d479aaedb6 (diff)
downloadpylint-git-03bfeff94692821f7f06e5c6bec42476358b289f.tar.gz
[FileState] Make Pylinter.current_name and msg_store non nullable
Diffstat (limited to 'pylint/lint')
-rw-r--r--pylint/lint/message_state_handler.py3
-rw-r--r--pylint/lint/parallel.py16
-rw-r--r--pylint/lint/pylinter.py24
3 files changed, 7 insertions, 36 deletions
diff --git a/pylint/lint/message_state_handler.py b/pylint/lint/message_state_handler.py
index ddeeaa7bc..b915df737 100644
--- a/pylint/lint/message_state_handler.py
+++ b/pylint/lint/message_state_handler.py
@@ -55,9 +55,8 @@ class _MessageStateHandler:
"enable-msg": self._options_methods["enable"],
}
self._pragma_lineno: dict[str, int] = {}
- # TODO: 3.0: Update key type to str when current_name is always str
self._stashed_messages: defaultdict[
- tuple[str | None, str], list[tuple[str | None, str]]
+ tuple[str, str], list[tuple[str | None, str]]
] = defaultdict(list)
"""Some messages in the options (for --enable and --disable) are encountered
too early to warn about them.
diff --git a/pylint/lint/parallel.py b/pylint/lint/parallel.py
index 544a256d3..a5e1a4665 100644
--- a/pylint/lint/parallel.py
+++ b/pylint/lint/parallel.py
@@ -5,7 +5,6 @@
from __future__ import annotations
import functools
-import warnings
from collections import defaultdict
from collections.abc import Iterable, Sequence
from typing import TYPE_CHECKING, Any
@@ -42,7 +41,7 @@ def _worker_initialize(
"""Function called to initialize a worker for a Process within a concurrent Pool.
:param linter: A linter-class (PyLinter) instance pickled with dill
- :param extra_packages_paths: Extra entries to be added to sys.path
+ :param extra_packages_paths: Extra entries to be added to `sys.path`
"""
global _worker_linter # pylint: disable=global-statement
_worker_linter = dill.loads(linter)
@@ -61,10 +60,9 @@ def _worker_check_single_file(
file_item: FileItem,
) -> tuple[
int,
- # TODO: 3.0: Make this only str after deprecation has been removed
- str | None,
str,
- str | None,
+ str,
+ str,
list[Message],
LinterStats,
int,
@@ -82,14 +80,6 @@ def _worker_check_single_file(
msgs = _worker_linter.reporter.messages
assert isinstance(_worker_linter.reporter, reporters.CollectingReporter)
_worker_linter.reporter.reset()
- if _worker_linter.current_name is None:
- warnings.warn(
- (
- "In pylint 3.0 the current_name attribute of the linter object should be a string. "
- "If unknown it should be initialized as an empty string."
- ),
- DeprecationWarning,
- )
return (
id(multiprocessing.current_process()),
_worker_linter.current_name,
diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py
index 143ad5c08..cec815ae5 100644
--- a/pylint/lint/pylinter.py
+++ b/pylint/lint/pylinter.py
@@ -339,7 +339,7 @@ class PyLinter(
# Attributes related to visiting files
self.file_state = FileState("", self.msgs_store, is_base_filestate=True)
- self.current_name: str | None = None
+ self.current_name: str = ""
self.current_file: str | None = None
self._ignore_file = False
self._ignore_paths: list[Pattern[str]] = []
@@ -900,26 +900,13 @@ class PyLinter(
self.add_message(key, args=message)
return result
- def set_current_module(
- self, modname: str | None, filepath: str | None = None
- ) -> None:
+ def set_current_module(self, modname: str, filepath: str | None = None) -> None:
"""Set the name of the currently analyzed module and
init statistics for it.
"""
if not modname and filepath is None:
return
self.reporter.on_set_current_module(modname or "", filepath)
- if modname is None:
- # TODO: 3.0: Remove all modname or ""'s in this method
- warnings.warn(
- (
- "In pylint 3.0 modname should be a string so that it can be used to "
- "correctly set the current_name attribute of the linter instance. "
- "If unknown it should be initialized as an empty string."
- ),
- DeprecationWarning,
- stacklevel=2,
- )
self.current_name = modname
self.current_file = filepath or modname
self.stats.init_single_module(modname or "")
@@ -1219,12 +1206,7 @@ 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)
- # TODO: 3.0 Should be removable after https://github.com/PyCQA/pylint/pull/5580
- self.stats.increase_single_module_message_count(
- self.current_name, # type: ignore[arg-type]
- msg_cat,
- 1,
- )
+ self.stats.increase_single_module_message_count(self.current_name, msg_cat, 1)
try:
self.stats.by_msg[message_definition.symbol] += 1
except KeyError: