From 10f50a03fe9aa0c6f90892af7ae550ed0849a340 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 8 Feb 2023 22:04:01 +0100 Subject: [PATCH] Minor refactor to 'is_defined' (#8243) (#8244) (cherry picked from commit 13fbe689d5fbd8ef34da54a747a320f01ffa9432) Co-authored-by: Zen Lee <53538590+zenlyj@users.noreply.github.com> --- pylint/checkers/utils.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index 062b19a54e..357cc702ef 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -2194,16 +2194,14 @@ def is_class_attr(name: str, klass: nodes.ClassDef) -> bool: def is_defined(name: str, node: nodes.NodeNG) -> bool: - """Checks whether a node defines the given variable name.""" + """Searches for a tree node that defines the given variable name.""" is_defined_so_far = False - if isinstance(node, nodes.NamedExpr) and node.target.name == name: - return True + if isinstance(node, nodes.NamedExpr): + is_defined_so_far = node.target.name == name - if isinstance(node, (nodes.Import, nodes.ImportFrom)) and any( - node_name[0] == name for node_name in node.names - ): - return True + if isinstance(node, (nodes.Import, nodes.ImportFrom)): + is_defined_so_far = any(node_name[0] == name for node_name in node.names) if isinstance(node, nodes.With): is_defined_so_far = any(