From 8bdfaaac03a7dfd9c9b01c412978690718e0ff9c Mon Sep 17 00:00:00 2001 From: Nick Drozd Date: Tue, 1 Oct 2024 18:10:06 -0400 Subject: [PATCH] Return directly from incompatible branches in _should_node_be_skipped --- pylint/checkers/variables.py | 39 +++++++++++++++++------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 5cb41e2fc6..01d8cd3189 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -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