Skip to content

Commit 10f50a0

Browse files
Minor refactor to 'is_defined' (#8243) (#8244)
(cherry picked from commit 13fbe68) Co-authored-by: Zen Lee <[email protected]>
1 parent 8b3a10f commit 10f50a0

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

pylint/checkers/utils.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -2194,16 +2194,14 @@ def is_class_attr(name: str, klass: nodes.ClassDef) -> bool:
21942194

21952195

21962196
def is_defined(name: str, node: nodes.NodeNG) -> bool:
2197-
"""Checks whether a node defines the given variable name."""
2197+
"""Searches for a tree node that defines the given variable name."""
21982198
is_defined_so_far = False
21992199

2200-
if isinstance(node, nodes.NamedExpr) and node.target.name == name:
2201-
return True
2200+
if isinstance(node, nodes.NamedExpr):
2201+
is_defined_so_far = node.target.name == name
22022202

2203-
if isinstance(node, (nodes.Import, nodes.ImportFrom)) and any(
2204-
node_name[0] == name for node_name in node.names
2205-
):
2206-
return True
2203+
if isinstance(node, (nodes.Import, nodes.ImportFrom)):
2204+
is_defined_so_far = any(node_name[0] == name for node_name in node.names)
22072205

22082206
if isinstance(node, nodes.With):
22092207
is_defined_so_far = any(

0 commit comments

Comments
 (0)