diff options
-rw-r--r-- | examples/custom_raw.py | 4 | ||||
-rw-r--r-- | pylint/checkers/format.py | 2 | ||||
-rw-r--r-- | pylint/checkers/misc.py | 12 | ||||
-rw-r--r-- | pylint/checkers/similar.py | 2 | ||||
-rw-r--r-- | pylint/checkers/strings.py | 4 | ||||
-rw-r--r-- | pylint/extensions/empty_comment.py | 4 | ||||
-rw-r--r-- | pylint/interfaces.py | 4 | ||||
-rw-r--r-- | tests/benchmark/test_baseline_benchmarks.py | 7 | ||||
-rw-r--r-- | tests/test_check_parallel.py | 6 |
9 files changed, 27 insertions, 18 deletions
diff --git a/examples/custom_raw.py b/examples/custom_raw.py index 63e4aeb8e..5f747869f 100644 --- a/examples/custom_raw.py +++ b/examples/custom_raw.py @@ -1,3 +1,5 @@ +from astroid import nodes + from pylint.checkers import BaseChecker from pylint.interfaces import IRawChecker @@ -22,7 +24,7 @@ class MyRawChecker(BaseChecker): } options = () - def process_module(self, node): + def process_module(self, node: nodes.Module) -> None: """process a module the module's content is accessible via node.stream() function diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py index ffd1b2169..62064b88b 100644 --- a/pylint/checkers/format.py +++ b/pylint/checkers/format.py @@ -351,7 +351,7 @@ class FormatChecker(BaseTokenChecker): self._lines[line_num] = line.split("\n")[0] self.check_lines(line, line_num) - def process_module(self, _module): + def process_module(self, _node: nodes.Module) -> None: pass def _check_keyword_parentheses( diff --git a/pylint/checkers/misc.py b/pylint/checkers/misc.py index e53935adf..60d30c91b 100644 --- a/pylint/checkers/misc.py +++ b/pylint/checkers/misc.py @@ -29,6 +29,8 @@ import re import tokenize +from astroid import nodes + from pylint.checkers import BaseChecker from pylint.interfaces import IRawChecker, ITokenChecker from pylint.message import MessagesHandlerMixIn @@ -50,11 +52,11 @@ class ByIdManagedMessagesChecker(BaseChecker): } options = () - def process_module(self, module): + def process_module(self, node: nodes.Module) -> None: """Inspect the source file to find messages activated or deactivated by id.""" managed_msgs = MessagesHandlerMixIn.get_by_id_managed_msgs() for (mod_name, msgid, symbol, lineno, is_disabled) in managed_msgs: - if mod_name == module.name: + if mod_name == node.name: verb = "disable" if is_disabled else "enable" txt = f"'{msgid}' is cryptic: use '# pylint: {verb}={symbol}' instead" self.add_message("use-symbolic-message-instead", line=lineno, args=txt) @@ -125,11 +127,11 @@ class EncodingChecker(BaseChecker): self.add_message("syntax-error", line=lineno, args=msg) return None - def process_module(self, module): + def process_module(self, node: nodes.Module) -> None: """inspect the source file to find encoding problem""" - encoding = module.file_encoding if module.file_encoding else "ascii" + encoding = node.file_encoding if node.file_encoding else "ascii" - with module.stream() as stream: + with node.stream() as stream: for lineno, line in enumerate(stream): self._check_encoding(lineno + 1, line, encoding) diff --git a/pylint/checkers/similar.py b/pylint/checkers/similar.py index 88d7eac52..fb92e7035 100644 --- a/pylint/checkers/similar.py +++ b/pylint/checkers/similar.py @@ -820,7 +820,7 @@ class SimilarChecker(BaseChecker, Similar, MapReduceMixin): nb_duplicated_lines=0, percent_duplicated_lines=0 ) - def process_module(self, node): + def process_module(self, node: nodes.Module) -> None: """process a module the module's content is accessible via the stream object diff --git a/pylint/checkers/strings.py b/pylint/checkers/strings.py index d05fc3c30..ae020594f 100644 --- a/pylint/checkers/strings.py +++ b/pylint/checkers/strings.py @@ -710,8 +710,8 @@ class StringConstantChecker(BaseTokenChecker): super().__init__(*args, **kwargs) self.string_tokens = {} # token position -> (token value, next token) - def process_module(self, module): - self._unicode_literals = "unicode_literals" in module.future_imports + def process_module(self, node: nodes.Module) -> None: + self._unicode_literals = "unicode_literals" in node.future_imports def process_tokens(self, tokens): encoding = "ascii" diff --git a/pylint/extensions/empty_comment.py b/pylint/extensions/empty_comment.py index a6f2ede75..7b9841678 100644 --- a/pylint/extensions/empty_comment.py +++ b/pylint/extensions/empty_comment.py @@ -1,3 +1,5 @@ +from astroid import nodes + from pylint.checkers import BaseChecker from pylint.interfaces import IRawChecker @@ -43,7 +45,7 @@ class CommentChecker(BaseChecker): options = () priority = -1 # low priority - def process_module(self, node): + def process_module(self, node: nodes.Module) -> None: with node.stream() as stream: for (line_num, line) in enumerate(stream): line = line.rstrip() diff --git a/pylint/interfaces.py b/pylint/interfaces.py index 02ed031f9..cac7e76c3 100644 --- a/pylint/interfaces.py +++ b/pylint/interfaces.py @@ -18,6 +18,8 @@ """Interfaces for Pylint objects""" from collections import namedtuple +from astroid import nodes + Confidence = namedtuple("Confidence", ["name", "description"]) # Warning Certainties HIGH = Confidence("HIGH", "No false positive possible.") @@ -66,7 +68,7 @@ class IChecker(Interface): class IRawChecker(IChecker): """interface for checker which need to parse the raw file""" - def process_module(self, astroid): + def process_module(self, node: nodes.Module) -> None: """process a module the module's content is accessible via astroid.stream diff --git a/tests/benchmark/test_baseline_benchmarks.py b/tests/benchmark/test_baseline_benchmarks.py index 693fe4d68..27dada39d 100644 --- a/tests/benchmark/test_baseline_benchmarks.py +++ b/tests/benchmark/test_baseline_benchmarks.py @@ -16,6 +16,7 @@ import time from unittest.mock import patch import pytest +from astroid import nodes import pylint.interfaces from pylint.checkers.base_checker import BaseChecker @@ -50,7 +51,7 @@ class SleepingChecker(BaseChecker): } sleep_duration = 0.5 # the time to pretend we're doing work for - def process_module(self, _astroid): + def process_module(self, _node: nodes.Module) -> None: """Sleeps for `sleep_duration` on each call This effectively means each file costs ~`sleep_duration`+framework overhead""" @@ -75,7 +76,7 @@ class SleepingCheckerLong(BaseChecker): } sleep_duration = 0.5 # the time to pretend we're doing work for - def process_module(self, _astroid): + def process_module(self, _node: nodes.Module) -> None: """Sleeps for `sleep_duration` on each call This effectively means each file costs ~`sleep_duration`+framework overhead""" @@ -96,7 +97,7 @@ class NoWorkChecker(BaseChecker): ) } - def process_module(self, _astroid): + def process_module(self, _node: nodes.Module) -> None: pass diff --git a/tests/test_check_parallel.py b/tests/test_check_parallel.py index f87f81845..102c0f122 100644 --- a/tests/test_check_parallel.py +++ b/tests/test_check_parallel.py @@ -14,7 +14,7 @@ import os from typing import List, Tuple import pytest -from astroid.nodes.scoped_nodes import Module +from astroid import nodes import pylint.interfaces import pylint.lint.parallel @@ -63,7 +63,7 @@ class SequentialTestChecker(BaseChecker): self.data: List[str] = [] self.linter = linter - def process_module(self, _astroid: Module) -> None: + def process_module(self, _node: nodes.Module) -> None: """Called once per stream/file/astroid object""" # record the number of invocations with the data object record = self.test_data + str(len(self.data)) @@ -125,7 +125,7 @@ class ParallelTestChecker(BaseChecker): self.add_message("R9999", args=("From reduce_map_data",)) recombined.close() - def process_module(self, _astroid: Module) -> None: + def process_module(self, _node: nodes.Module) -> None: """Called once per stream/file/astroid object""" # record the number of invocations with the data object record = self.test_data + str(len(self.data)) |