Skip to content
Merged
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
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-next=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