summaryrefslogtreecommitdiff
path: root/pylint/checkers/raw_metrics.py
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2022-04-19 17:16:59 +0200
committerGitHub <noreply@github.com>2022-04-19 17:16:59 +0200
commit58a4067d4b70c5e05eca23d57c3e6ad30d1788bd (patch)
treee921a773234b57e298cbb17c64426c802633035e /pylint/checkers/raw_metrics.py
parentac6efbff8ba8145407dad16b927b8b9df5976ee6 (diff)
downloadpylint-git-58a4067d4b70c5e05eca23d57c3e6ad30d1788bd.tar.gz
Add typing to BaseChecker.process_token (#6273)
Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
Diffstat (limited to 'pylint/checkers/raw_metrics.py')
-rw-r--r--pylint/checkers/raw_metrics.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/pylint/checkers/raw_metrics.py b/pylint/checkers/raw_metrics.py
index 9e0fe08f1..3940bcfff 100644
--- a/pylint/checkers/raw_metrics.py
+++ b/pylint/checkers/raw_metrics.py
@@ -73,7 +73,7 @@ class RawMetricsChecker(BaseTokenChecker):
"""Init statistics."""
self.linter.stats.reset_code_count()
- def process_tokens(self, tokens):
+ def process_tokens(self, tokens: list[tokenize.TokenInfo]) -> None:
"""Update stats."""
i = 0
tokens = list(tokens)
@@ -86,7 +86,9 @@ class RawMetricsChecker(BaseTokenChecker):
JUNK = (tokenize.NL, tokenize.INDENT, tokenize.NEWLINE, tokenize.ENDMARKER)
-def get_type(tokens, start_index):
+def get_type(
+ tokens: list[tokenize.TokenInfo], start_index: int
+) -> tuple[int, int, Literal["code", "docstring", "comment", "empty"]]:
"""Return the line type : docstring, comment, code, empty."""
i = start_index
start = tokens[i][2]
@@ -109,7 +111,8 @@ def get_type(tokens, start_index):
line_type = "empty"
elif i < len(tokens) and tokens[i][0] == tokenize.NEWLINE:
i += 1
- return i, pos[0] - start[0] + 1, line_type
+ # Mypy fails to infer the literal of line_type
+ return i, pos[0] - start[0] + 1, line_type # type: ignore[return-value]
def register(linter: PyLinter) -> None: