Skip to content

Commit

Permalink
Return directly from incompatible branches in _should_node_be_skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Oct 1, 2024
1 parent 113fc2b commit a097e4e
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1726,32 +1726,29 @@ def _should_node_be_skipped(
# scope, ignore it. This prevents to access this scope instead of
# the globals one in function members when there are some common
# names.
if utils.is_ancestor_name(consumer.node, node) or (
not is_start_index and self._ignore_class_scope(node)
):
return True

# Ignore inner class scope for keywords in class definition
if isinstance(node.parent, nodes.Keyword) and isinstance(
node.parent.parent, nodes.ClassDef
):
return True

elif consumer.scope_type == "function" and self._defined_in_function_definition(
node, consumer.node
):
if any(node.name == param.name.name for param in consumer.node.type_params):
return False
return (
utils.is_ancestor_name(consumer.node, node)
or (not is_start_index and self._ignore_class_scope(node))
# Ignore inner class scope for keywords in class definition
or (
isinstance(node.parent, nodes.Keyword)
and isinstance(node.parent.parent, nodes.ClassDef)
)
)

if consumer.scope_type == "function":
# If the name node is used as a function default argument's value or as
# a decorator, then start from the parent frame of the function instead
# of the function frame - and thus open an inner class scope
return True
return self._defined_in_function_definition(
node,
consumer.node,
) and not any(
node.name == param.name.name for param in consumer.node.type_params
)

elif consumer.scope_type == "lambda" and utils.is_default_argument(
node, consumer.node
):
return True
if consumer.scope_type == "lambda":
return utils.is_default_argument(node, consumer.node)

return False

Expand Down

0 comments on commit a097e4e

Please sign in to comment.