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

Catch ParentMissingError in variables checker #9371

Merged
merged 3 commits into from
Jan 28, 2024
Merged
Changes from 2 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
11 changes: 8 additions & 3 deletions pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import TYPE_CHECKING, Any, NamedTuple

import astroid
import astroid.exceptions
from astroid import bases, extract_node, nodes, util
from astroid.nodes import _base_nodes
from astroid.typing import InferenceResult
Expand Down Expand Up @@ -2511,7 +2512,7 @@ class D(Tp):
and name in frame_locals
)

# pylint: disable = too-many-branches
# pylint: disable = too-many-branches, too-many-statements
def _loopvar_name(self, node: astroid.Name) -> None:
# filter variables according to node's scope
astmts = [s for s in node.lookup(node.name)[1] if hasattr(s, "assign_type")]
Expand Down Expand Up @@ -2547,8 +2548,12 @@ def _loopvar_name(self, node: astroid.Name) -> None:
else:
_astmts = astmts[:1]
for i, stmt in enumerate(astmts[1:]):
if astmts[i].statement().parent_of(stmt) and not utils.in_for_else_branch(
astmts[i].statement(), stmt
try:
astmt_statement = astmts[i].statement()
except astroid.exceptions.ParentMissingError:
continue
if astmt_statement.parent_of(stmt) and not utils.in_for_else_branch(
astmt_statement, stmt
):
continue
_astmts.append(stmt)
Expand Down
Loading