Skip to content

Commit

Permalink
Minor refactor to 'is_defined' (#8243)
Browse files Browse the repository at this point in the history
(cherry picked from commit 13fbe68)
  • Loading branch information
zenlyj authored and github-actions[bot] committed Feb 8, 2023
1 parent 8b3a10f commit 6d78ed2
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 6d78ed2

Please sign in to comment.