Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix astroid base_nodes imports #9394

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -850,7 +850,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 @@ -1071,7 +1071,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 @@ -1091,7 +1091,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 @@ -1139,7 +1139,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 @@ -2183,8 +2183,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 @@ -2338,7 +2338,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 @@ -2380,7 +2380,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
Loading