diff options
author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-06-09 04:28:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-09 04:28:32 +0200 |
commit | c05ca30fa2c4d921f092a84d4cfd7251c2af9371 (patch) | |
tree | 7c76cca5b89f2b931e75374655e941fe196833d4 /pylint/extensions | |
parent | 72855d5d08a91ca5faa8c5442ff6f4aedfadf7ca (diff) | |
download | pylint-git-c05ca30fa2c4d921f092a84d4cfd7251c2af9371.tar.gz |
Add typing to extensions (#6893)
Diffstat (limited to 'pylint/extensions')
-rw-r--r-- | pylint/extensions/_check_docs_utils.py | 3 | ||||
-rw-r--r-- | pylint/extensions/broad_try_clause.py | 2 | ||||
-rw-r--r-- | pylint/extensions/check_elif.py | 7 | ||||
-rw-r--r-- | pylint/extensions/docparams.py | 40 | ||||
-rw-r--r-- | pylint/extensions/redefined_variable_type.py | 4 |
5 files changed, 31 insertions, 25 deletions
diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py index dacdbe05e..3f4937f17 100644 --- a/pylint/extensions/_check_docs_utils.py +++ b/pylint/extensions/_check_docs_utils.py @@ -10,6 +10,7 @@ import re import astroid from astroid import nodes +from astroid.util import Uninferable from pylint.checkers import utils @@ -88,7 +89,7 @@ def returns_something(return_node: nodes.Return) -> bool: return not (isinstance(returns, nodes.Const) and returns.value is None) -def _get_raise_target(node): +def _get_raise_target(node: nodes.NodeNG) -> nodes.NodeNG | Uninferable | None: if isinstance(node.exc, nodes.Call): func = node.exc.func if isinstance(func, (nodes.Name, nodes.Attribute)): diff --git a/pylint/extensions/broad_try_clause.py b/pylint/extensions/broad_try_clause.py index bfbb7c9e9..76c835bf0 100644 --- a/pylint/extensions/broad_try_clause.py +++ b/pylint/extensions/broad_try_clause.py @@ -46,7 +46,7 @@ class BroadTryClauseChecker(checkers.BaseChecker): ), ) - def _count_statements(self, try_node): + def _count_statements(self, try_node: nodes.TryExcept | nodes.TryFinally) -> int: statement_count = len(try_node.body) for body_node in try_node.body: diff --git a/pylint/extensions/check_elif.py b/pylint/extensions/check_elif.py index 53eec7f7e..b584ea35e 100644 --- a/pylint/extensions/check_elif.py +++ b/pylint/extensions/check_elif.py @@ -4,6 +4,7 @@ from __future__ import annotations +import tokenize from tokenize import TokenInfo from typing import TYPE_CHECKING @@ -31,12 +32,12 @@ class ElseifUsedChecker(BaseTokenChecker): ) } - def __init__(self, linter=None): + def __init__(self, linter: PyLinter) -> None: super().__init__(linter) self._init() - def _init(self): - self._elifs = {} + def _init(self) -> None: + self._elifs: dict[tokenize._Position, str] = {} def process_tokens(self, tokens: list[TokenInfo]) -> None: """Process tokens and look for 'if' or 'elif'.""" diff --git a/pylint/extensions/docparams.py b/pylint/extensions/docparams.py index 7e0dc12c3..68a30a39c 100644 --- a/pylint/extensions/docparams.py +++ b/pylint/extensions/docparams.py @@ -216,7 +216,9 @@ class DocstringParameterChecker(BaseChecker): visit_asyncfunctiondef = visit_functiondef - def check_functiondef_params(self, node, node_doc): + def check_functiondef_params( + self, node: nodes.FunctionDef, node_doc: Docstring + ) -> None: node_allow_no_param = None if node.name in self.constructor_names: class_node = checker_utils.node_frame_class(node) @@ -247,7 +249,9 @@ class DocstringParameterChecker(BaseChecker): node_doc, node.args, node, node_allow_no_param ) - def check_functiondef_returns(self, node, node_doc): + def check_functiondef_returns( + self, node: nodes.FunctionDef, node_doc: Docstring + ) -> None: if (not node_doc.supports_yields and node.is_generator()) or node.is_abstract(): return @@ -257,7 +261,9 @@ class DocstringParameterChecker(BaseChecker): ): self.add_message("redundant-returns-doc", node=node) - def check_functiondef_yields(self, node, node_doc): + def check_functiondef_yields( + self, node: nodes.FunctionDef, node_doc: Docstring + ) -> None: if not node_doc.supports_yields or node.is_abstract(): return @@ -446,25 +452,21 @@ class DocstringParameterChecker(BaseChecker): def _compare_ignored_args( self, - found_argument_names, - message_id, - ignored_argument_names, - warning_node, - ): + found_argument_names: set[str], + message_id: str, + ignored_argument_names: set[str], + warning_node: nodes.NodeNG, + ) -> None: """Compare the found argument names with the ignored ones and generate a message if there are ignored arguments found. :param found_argument_names: argument names found in the docstring - :type found_argument_names: set :param message_id: pylint message id - :type message_id: str :param ignored_argument_names: Expected argument names - :type ignored_argument_names: set :param warning_node: The node to be analyzed - :type warning_node: :class:`astroid.scoped_nodes.Node` """ existing_ignored_argument_names = ignored_argument_names & found_argument_names @@ -481,7 +483,7 @@ class DocstringParameterChecker(BaseChecker): arguments_node: astroid.Arguments, warning_node: astroid.NodeNG, accept_no_param_doc: bool | None = None, - ): + ) -> None: """Check that all parameters are consistent with the parameters mentioned in the parameter documentation (e.g. the Sphinx tags 'param' and 'type'). @@ -616,26 +618,28 @@ class DocstringParameterChecker(BaseChecker): warning_node, ) - def check_single_constructor_params(self, class_doc, init_doc, class_node): + def check_single_constructor_params( + self, class_doc: Docstring, init_doc: Docstring, class_node: nodes.ClassDef + ) -> None: if class_doc.has_params() and init_doc.has_params(): self.add_message( "multiple-constructor-doc", args=(class_node.name,), node=class_node ) - def _handle_no_raise_doc(self, excs, node): + def _handle_no_raise_doc(self, excs: set[str], node: nodes.FunctionDef) -> None: if self.linter.config.accept_no_raise_doc: return self._add_raise_message(excs, node) - def _add_raise_message(self, missing_excs, node): + def _add_raise_message( + self, missing_excs: set[str], node: nodes.FunctionDef + ) -> None: """Adds a message on :param:`node` for the missing exception type. :param missing_excs: A list of missing exception types. - :type missing_excs: set(str) :param node: The node show the message on. - :type node: nodes.NodeNG """ if node.is_abstract(): try: diff --git a/pylint/extensions/redefined_variable_type.py b/pylint/extensions/redefined_variable_type.py index 994d42278..ae7344cc1 100644 --- a/pylint/extensions/redefined_variable_type.py +++ b/pylint/extensions/redefined_variable_type.py @@ -50,9 +50,9 @@ class MultipleTypesChecker(BaseChecker): leave_functiondef = leave_module = leave_classdef def visit_module(self, _: nodes.Module) -> None: - self._assigns: list[dict] = [{}] + self._assigns: list[dict[str, list[tuple[nodes.Assign, str]]]] = [{}] - def _check_and_add_messages(self): + def _check_and_add_messages(self) -> None: assigns = self._assigns.pop() for name, args in assigns.items(): if len(args) <= 1: |