Skip to content

Commit

Permalink
Fix astroid base_nodes imports (#9394)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Jan 31, 2024
1 parent 32b2444 commit 6062c1d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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] = []
(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6062c1d

Please sign in to comment.