Skip to content

Commit

Permalink
Fix annotations for statement method (#2366) (#2368)
Browse files Browse the repository at this point in the history
(cherry picked from commit 3e8f21d)

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and cdce8p authored Jan 31, 2024
1 parent e6dea9c commit 9061552
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions astroid/filter_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

def _get_filtered_node_statements(
base_node: nodes.NodeNG, stmt_nodes: list[nodes.NodeNG]
) -> list[tuple[nodes.NodeNG, nodes.Statement]]:
) -> list[tuple[nodes.NodeNG, _base_nodes.Statement]]:
statements = [(node, node.statement()) for node in stmt_nodes]
# Next we check if we have ExceptHandlers that are parent
# of the underlying variable, in which case the last one survives
Expand Down Expand Up @@ -90,7 +90,7 @@ def _filter_stmts(
if base_node.parent and base_node.statement() is myframe and myframe.parent:
myframe = myframe.parent.frame()

mystmt: nodes.Statement | None = None
mystmt: _base_nodes.Statement | None = None
if base_node.parent:
mystmt = base_node.statement()

Expand Down
5 changes: 3 additions & 2 deletions astroid/nodes/node_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

if TYPE_CHECKING:
from astroid import nodes
from astroid.nodes import _base_nodes


# Types for 'NodeNG.nodes_of_class()'
Expand Down Expand Up @@ -278,7 +279,7 @@ def parent_of(self, node) -> bool:
"""
return any(self is parent for parent in node.node_ancestors())

def statement(self, *, future: Literal[None, True] = None) -> nodes.Statement:
def statement(self, *, future: Literal[None, True] = None) -> _base_nodes.Statement:
"""The first parent node, including self, marked as statement node.
:raises StatementMissing: If self has no parent attribute.
Expand All @@ -290,7 +291,7 @@ def statement(self, *, future: Literal[None, True] = None) -> nodes.Statement:
stacklevel=2,
)
if self.is_statement:
return cast("nodes.Statement", self)
return cast("_base_nodes.Statement", self)
if not self.parent:
raise StatementMissing(target=self)
return self.parent.statement()
Expand Down

0 comments on commit 9061552

Please sign in to comment.