Skip to content

Commit

Permalink
Minor refactor to 'is_defined' (#8243) (#8244)
Browse files Browse the repository at this point in the history
(cherry picked from commit 13fbe68)

Co-authored-by: Zen Lee <53538590+zenlyj@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and zenlyj authored Feb 8, 2023
1 parent 8b3a10f commit 10f50a0
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 10f50a0

Please sign in to comment.