Skip to content

Commit ce9b7cb

Browse files
Fix astroid base_nodes imports (#9394) (#9404)
(cherry picked from commit 6062c1d) Co-authored-by: Marc Mueller <[email protected]>
1 parent b2b54cd commit ce9b7cb

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

pylint/checkers/typecheck.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import astroid.exceptions
2222
import astroid.helpers
2323
from astroid import arguments, bases, nodes, util
24+
from astroid.nodes import _base_nodes
2425
from astroid.typing import InferenceResult, SuccessfulInferenceResult
2526

2627
from pylint.checkers import BaseChecker, utils
@@ -660,7 +661,7 @@ def _determine_callable(
660661
def _has_parent_of_type(
661662
node: nodes.Call,
662663
node_type: nodes.Keyword | nodes.Starred,
663-
statement: nodes.Statement,
664+
statement: _base_nodes.Statement,
664665
) -> bool:
665666
"""Check if the given node has a parent of the given type."""
666667
parent = node.parent

pylint/checkers/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from astroid import TooManyLevelsError, nodes, util
2323
from astroid.context import InferenceContext
2424
from astroid.exceptions import AstroidError
25-
from astroid.nodes._base_nodes import ImportNode
25+
from astroid.nodes._base_nodes import ImportNode, Statement
2626
from astroid.typing import InferenceResult, SuccessfulInferenceResult
2727

2828
if TYPE_CHECKING:
@@ -1986,7 +1986,7 @@ def is_typing_member(node: nodes.NodeNG, names_to_check: tuple[str, ...]) -> boo
19861986

19871987

19881988
@lru_cache
1989-
def in_for_else_branch(parent: nodes.NodeNG, stmt: nodes.Statement) -> bool:
1989+
def in_for_else_branch(parent: nodes.NodeNG, stmt: Statement) -> bool:
19901990
"""Returns True if stmt is inside the else branch for a parent For stmt."""
19911991
return isinstance(parent, nodes.For) and any(
19921992
else_stmt.parent_of(stmt) or else_stmt == stmt for else_stmt in parent.orelse

pylint/checkers/variables.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ def _node_guarded_by_same_test(node: nodes.NodeNG, other_if: nodes.If) -> bool:
850850
def _uncertain_nodes_in_except_blocks(
851851
found_nodes: list[nodes.NodeNG],
852852
node: nodes.NodeNG,
853-
node_statement: nodes.Statement,
853+
node_statement: _base_nodes.Statement,
854854
) -> list[nodes.NodeNG]:
855855
"""Return any nodes in ``found_nodes`` that should be treated as uncertain
856856
because they are in an except block.
@@ -1071,7 +1071,7 @@ def _try_in_loop_body(
10711071

10721072
@staticmethod
10731073
def _recursive_search_for_continue_before_break(
1074-
stmt: nodes.Statement, break_stmt: nodes.Break
1074+
stmt: _base_nodes.Statement, break_stmt: nodes.Break
10751075
) -> bool:
10761076
"""Return True if any Continue node can be found in descendants of `stmt`
10771077
before encountering `break_stmt`, ignoring any nested loops.
@@ -1091,7 +1091,7 @@ def _recursive_search_for_continue_before_break(
10911091

10921092
@staticmethod
10931093
def _uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
1094-
found_nodes: list[nodes.NodeNG], node_statement: nodes.Statement
1094+
found_nodes: list[nodes.NodeNG], node_statement: _base_nodes.Statement
10951095
) -> list[nodes.NodeNG]:
10961096
"""Return any nodes in ``found_nodes`` that should be treated as uncertain.
10971097
@@ -1139,7 +1139,7 @@ def _uncertain_nodes_in_try_blocks_when_evaluating_except_blocks(
11391139

11401140
@staticmethod
11411141
def _uncertain_nodes_in_try_blocks_when_evaluating_finally_blocks(
1142-
found_nodes: list[nodes.NodeNG], node_statement: nodes.Statement
1142+
found_nodes: list[nodes.NodeNG], node_statement: _base_nodes.Statement
11431143
) -> list[nodes.NodeNG]:
11441144
uncertain_nodes: list[nodes.NodeNG] = []
11451145
(
@@ -2183,8 +2183,8 @@ def _in_lambda_or_comprehension_body(
21832183
def _is_variable_violation(
21842184
node: nodes.Name,
21852185
defnode: nodes.NodeNG,
2186-
stmt: nodes.Statement,
2187-
defstmt: nodes.Statement,
2186+
stmt: _base_nodes.Statement,
2187+
defstmt: _base_nodes.Statement,
21882188
frame: nodes.LocalsDictNodeNG, # scope of statement of node
21892189
defframe: nodes.LocalsDictNodeNG,
21902190
base_scope_type: str,
@@ -2338,7 +2338,7 @@ def _is_variable_violation(
23382338
return maybe_before_assign, annotation_return, use_outer_definition
23392339

23402340
@staticmethod
2341-
def _maybe_used_and_assigned_at_once(defstmt: nodes.Statement) -> bool:
2341+
def _maybe_used_and_assigned_at_once(defstmt: _base_nodes.Statement) -> bool:
23422342
"""Check if `defstmt` has the potential to use and assign a name in the
23432343
same statement.
23442344
"""
@@ -2380,7 +2380,9 @@ def _is_builtin(self, name: str) -> bool:
23802380
return name in self.linter.config.additional_builtins or utils.is_builtin(name)
23812381

23822382
@staticmethod
2383-
def _is_only_type_assignment(node: nodes.Name, defstmt: nodes.Statement) -> bool:
2383+
def _is_only_type_assignment(
2384+
node: nodes.Name, defstmt: _base_nodes.Statement
2385+
) -> bool:
23842386
"""Check if variable only gets assigned a type and never a value."""
23852387
if not isinstance(defstmt, nodes.AnnAssign) or defstmt.value:
23862388
return False

0 commit comments

Comments
 (0)