diff options
author | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-06-06 15:16:58 +0200 |
---|---|---|
committer | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-06-06 15:38:53 +0200 |
commit | 0777a0ecb5c730acfa54186c56af508692bec821 (patch) | |
tree | 2d7e85e09d3ac2b128d397951ffcb6a7b0fb6b05 /pylint/extensions | |
parent | d54338d30bf782b20e6792964bbddd1ddfaa256b (diff) | |
download | pylint-git-0777a0ecb5c730acfa54186c56af508692bec821.tar.gz |
Add typing to several checkers
Diffstat (limited to 'pylint/extensions')
-rw-r--r-- | pylint/extensions/comparetozero.py | 19 | ||||
-rw-r--r-- | pylint/extensions/comparison_placement.py | 2 | ||||
-rw-r--r-- | pylint/extensions/confusing_elif.py | 2 | ||||
-rw-r--r-- | pylint/extensions/docstyle.py | 6 | ||||
-rw-r--r-- | pylint/extensions/empty_comment.py | 4 |
5 files changed, 17 insertions, 16 deletions
diff --git a/pylint/extensions/comparetozero.py b/pylint/extensions/comparetozero.py index dd0f1949a..8aca300d2 100644 --- a/pylint/extensions/comparetozero.py +++ b/pylint/extensions/comparetozero.py @@ -7,8 +7,7 @@ from __future__ import annotations import itertools -from collections.abc import Iterable -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING import astroid from astroid import nodes @@ -20,7 +19,7 @@ if TYPE_CHECKING: from pylint.lint import PyLinter -def _is_constant_zero(node): +def _is_constant_zero(node: str | nodes.NodeNG) -> bool: return isinstance(node, astroid.Const) and node.value == 0 @@ -52,15 +51,15 @@ class CompareToZeroChecker(checkers.BaseChecker): # while the rest are a list of tuples in node.ops # the format of the tuple is ('compare operator sign', node) # here we squash everything into `ops` to make it easier for processing later - ops = [("", node.left)] + ops: list[tuple[str, nodes.NodeNG]] = [("", node.left)] ops.extend(node.ops) - iter_ops: Iterable[Any] = iter(ops) - ops = list(itertools.chain(*iter_ops)) + iter_ops = iter(ops) + all_ops = list(itertools.chain(*iter_ops)) - for ops_idx in range(len(ops) - 2): - op_1 = ops[ops_idx] - op_2 = ops[ops_idx + 1] - op_3 = ops[ops_idx + 2] + for ops_idx in range(len(all_ops) - 2): + op_1 = all_ops[ops_idx] + op_2 = all_ops[ops_idx + 1] + op_3 = all_ops[ops_idx + 2] error_detected = False # 0 ?? X diff --git a/pylint/extensions/comparison_placement.py b/pylint/extensions/comparison_placement.py index 264b2402d..df7cc9890 100644 --- a/pylint/extensions/comparison_placement.py +++ b/pylint/extensions/comparison_placement.py @@ -45,7 +45,7 @@ class MisplacedComparisonConstantChecker(BaseChecker): left: nodes.NodeNG, right: nodes.NodeNG, operator: str, - ): + ) -> None: if isinstance(right, nodes.Const): return operator = REVERSED_COMPS.get(operator, operator) diff --git a/pylint/extensions/confusing_elif.py b/pylint/extensions/confusing_elif.py index 8e70cab60..174f464ac 100644 --- a/pylint/extensions/confusing_elif.py +++ b/pylint/extensions/confusing_elif.py @@ -40,7 +40,7 @@ class ConfusingConsecutiveElifChecker(BaseChecker): self.add_message("confusing-consecutive-elif", node=node.orelse[0]) @staticmethod - def _has_no_else_clause(node: nodes.If): + def _has_no_else_clause(node: nodes.If) -> bool: orelse = node.orelse while orelse and isinstance(orelse[0], nodes.If): orelse = orelse[0].orelse diff --git a/pylint/extensions/docstyle.py b/pylint/extensions/docstyle.py index 99b01563f..1ca2885e9 100644 --- a/pylint/extensions/docstyle.py +++ b/pylint/extensions/docstyle.py @@ -48,7 +48,9 @@ class DocStringStyleChecker(checkers.BaseChecker): visit_asyncfunctiondef = visit_functiondef - def _check_docstring(self, node_type, node): + def _check_docstring( + self, node_type: str, node: nodes.Module | nodes.ClassDef | nodes.FunctionDef + ) -> None: docstring = node.doc_node.value if node.doc_node else None if docstring and docstring[0] == "\n": self.add_message( @@ -73,7 +75,7 @@ class DocStringStyleChecker(checkers.BaseChecker): elif line and line[0] == "'": quotes = "'" else: - quotes = False + quotes = "" if quotes: self.add_message( "bad-docstring-quotes", diff --git a/pylint/extensions/empty_comment.py b/pylint/extensions/empty_comment.py index 70d3f67d2..5b60900c0 100644 --- a/pylint/extensions/empty_comment.py +++ b/pylint/extensions/empty_comment.py @@ -14,7 +14,7 @@ if TYPE_CHECKING: from pylint.lint import PyLinter -def is_line_commented(line): +def is_line_commented(line: bytes) -> bool: """Checks if a `# symbol that is not part of a string was found in line.""" comment_idx = line.find(b"#") @@ -25,7 +25,7 @@ def is_line_commented(line): return True -def comment_part_of_string(line, comment_idx): +def comment_part_of_string(line: bytes, comment_idx: int) -> bool: """Checks if the symbol at comment_idx is part of a string.""" if ( |