From 77caa0fa118e81b8dcf8266953b39ef37004b402 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 28 Jan 2024 09:28:28 -0500 Subject: [PATCH] Catch ParentMissingError in variables checker (#9371) --- pylint/checkers/variables.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index b13e25491a..a0d33639a2 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -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 @@ -2521,7 +2522,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")] @@ -2557,8 +2558,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)