Skip to content

Commit 6b5f217

Browse files
authored
Merge branch 'pylint-dev:main' into per_directory_configs
2 parents 3bd9d4a + 77caa0f commit 6b5f217

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pylint/checkers/variables.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import TYPE_CHECKING, Any, NamedTuple
2020

2121
import astroid
22+
import astroid.exceptions
2223
from astroid import bases, extract_node, nodes, util
2324
from astroid.nodes import _base_nodes
2425
from astroid.typing import InferenceResult
@@ -2521,7 +2522,7 @@ class D(Tp):
25212522
and name in frame_locals
25222523
)
25232524

2524-
# pylint: disable = too-many-branches
2525+
# pylint: disable-next=too-many-branches,too-many-statements
25252526
def _loopvar_name(self, node: astroid.Name) -> None:
25262527
# filter variables according to node's scope
25272528
astmts = [s for s in node.lookup(node.name)[1] if hasattr(s, "assign_type")]
@@ -2557,8 +2558,12 @@ def _loopvar_name(self, node: astroid.Name) -> None:
25572558
else:
25582559
_astmts = astmts[:1]
25592560
for i, stmt in enumerate(astmts[1:]):
2560-
if astmts[i].statement().parent_of(stmt) and not utils.in_for_else_branch(
2561-
astmts[i].statement(), stmt
2561+
try:
2562+
astmt_statement = astmts[i].statement()
2563+
except astroid.exceptions.ParentMissingError:
2564+
continue
2565+
if astmt_statement.parent_of(stmt) and not utils.in_for_else_branch(
2566+
astmt_statement, stmt
25622567
):
25632568
continue
25642569
_astmts.append(stmt)

0 commit comments

Comments
 (0)