summaryrefslogtreecommitdiff
path: root/pylint/checkers/utils.py
diff options
context:
space:
mode:
authorZen Lee <53538590+zenlyj@users.noreply.github.com>2023-02-09 03:31:12 +0800
committerGitHub <noreply@github.com>2023-02-08 20:31:12 +0100
commit13fbe689d5fbd8ef34da54a747a320f01ffa9432 (patch)
tree756a8ea781291b77fdceb1cb3e0db3a09aff55a1 /pylint/checkers/utils.py
parent74a8eb6cefb0b337f5f9af3c924bee45033e3ece (diff)
downloadpylint-git-13fbe689d5fbd8ef34da54a747a320f01ffa9432.tar.gz
Minor refactor to 'is_defined' (#8243)
Diffstat (limited to 'pylint/checkers/utils.py')
-rw-r--r--pylint/checkers/utils.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index 062b19a54..357cc702e 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(