Skip to content

Fix annotations for statement method #2366

New issue

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

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

Already on GitHub? Sign in to your account

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
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