From 6062c1d8bb16de5d1a9f14f51b265653483ad6dd Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Wed, 31 Jan 2024 16:05:08 +0100 Subject: [PATCH] Fix astroid base_nodes imports (#9394) --- pylint/checkers/typecheck.py | 3 ++- pylint/checkers/utils.py | 4 ++-- pylint/checkers/variables.py | 18 ++++++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 9c73fee82f..814c392f46 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -21,6 +21,7 @@ import astroid.exceptions import astroid.helpers from astroid import arguments, bases, nodes, util +from astroid.nodes import _base_nodes from astroid.typing import InferenceResult, SuccessfulInferenceResult from pylint.checkers import BaseChecker, utils @@ -660,7 +661,7 @@ def _determine_callable( def _has_parent_of_type( node: nodes.Call, node_type: nodes.Keyword | nodes.Starred, - statement: nodes.Statement, + statement: _base_nodes.Statement, ) -> bool: """Check if the given node has a parent of the given type.""" parent = node.parent diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index eb9d52d4d5..3b6a26db35 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -22,7 +22,7 @@ from astroid import TooManyLevelsError, nodes, util from astroid.context import InferenceContext from astroid.exceptions import AstroidError -from astroid.nodes._base_nodes import ImportNode +from astroid.nodes._base_nodes import ImportNode, Statement from astroid.typing import InferenceResult, SuccessfulInferenceResult if TYPE_CHECKING: @@ -1986,7 +1986,7 @@ def is_typing_member(node: nodes.NodeNG, names_to_check: tuple[str, ...]) -> boo @lru_cache -def in_for_else_branch(parent: nodes.NodeNG, stmt: nodes.Statement) -> bool: +def in_for_else_branch(parent: nodes.NodeNG, stmt: Statement) -> bool: """Returns True if stmt is inside the else branch for a parent For stmt.""" return isinstance(parent, nodes.For) and any( else_stmt.parent_of(stmt) or else_stmt == stmt for else_stmt in parent.orelse diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 9f71539d7b..6e9941529c 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -851,7 +851,7 @@ def _node_guarded_by_same_test(node: nodes.NodeNG, other_if: nodes.If) -> bool: def _uncertain_nodes_in_except_blocks( found_nodes: list[nodes.NodeNG], node: nodes.NodeNG, - node_statement: nodes.Statement, + node_statement: _base_nodes.Statement, ) -> list[nodes.NodeNG]: """Return any nodes in ``found_nodes`` that should be treated as uncertain because they are in an except block. @@ -1072,7 +1072,7 @@ def _try_in_loop_body( @staticmethod def _recursive_search_for_continue_before_break( - stmt: nodes.Statement, break_stmt: nodes.Break + stmt: _base_nodes.Statement, break_stmt: nodes.Break ) -> bool: """Return True if any Continue node can be found in descendants of `stmt` before encountering `break_stmt`, ignoring any nested loops. @@ -1092,7 +1092,7 @@ def _recursive_search_for_continue_before_break( @staticmethod def _uncertain_nodes_in_try_blocks_when_evaluating_except_blocks( - found_nodes: list[nodes.NodeNG], node_statement: nodes.Statement + found_nodes: list[nodes.NodeNG], node_statement: _base_nodes.Statement ) -> list[nodes.NodeNG]: """Return any nodes in ``found_nodes`` that should be treated as uncertain. @@ -1140,7 +1140,7 @@ def _uncertain_nodes_in_try_blocks_when_evaluating_except_blocks( @staticmethod def _uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks( - found_nodes: list[nodes.NodeNG], node_statement: nodes.Statement + found_nodes: list[nodes.NodeNG], node_statement: _base_nodes.Statement ) -> list[nodes.NodeNG]: uncertain_nodes: list[nodes.NodeNG] = [] ( @@ -2184,8 +2184,8 @@ def _in_lambda_or_comprehension_body( def _is_variable_violation( node: nodes.Name, defnode: nodes.NodeNG, - stmt: nodes.Statement, - defstmt: nodes.Statement, + stmt: _base_nodes.Statement, + defstmt: _base_nodes.Statement, frame: nodes.LocalsDictNodeNG, # scope of statement of node defframe: nodes.LocalsDictNodeNG, base_scope_type: str, @@ -2339,7 +2339,7 @@ def _is_variable_violation( return maybe_before_assign, annotation_return, use_outer_definition @staticmethod - def _maybe_used_and_assigned_at_once(defstmt: nodes.Statement) -> bool: + def _maybe_used_and_assigned_at_once(defstmt: _base_nodes.Statement) -> bool: """Check if `defstmt` has the potential to use and assign a name in the same statement. """ @@ -2381,7 +2381,9 @@ def _is_builtin(self, name: str) -> bool: return name in self.linter.config.additional_builtins or utils.is_builtin(name) @staticmethod - def _is_only_type_assignment(node: nodes.Name, defstmt: nodes.Statement) -> bool: + def _is_only_type_assignment( + node: nodes.Name, defstmt: _base_nodes.Statement + ) -> bool: """Check if variable only gets assigned a type and never a value.""" if not isinstance(defstmt, nodes.AnnAssign) or defstmt.value: return False