diff options
Diffstat (limited to 'pylint/checkers/variables.py')
-rw-r--r-- | pylint/checkers/variables.py | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 82b99a805..315698c58 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -1389,23 +1389,19 @@ class VariablesChecker(BaseChecker): # class A: # x = lambda attr: f + attr # f = 42 - if isinstance(frame, nodes.ClassDef) and node.name in frame.locals: - if isinstance(node.parent, nodes.Arguments): - if stmt.fromlineno <= defstmt.fromlineno: - # Doing the following is fine: - # class A: - # x = 42 - # y = lambda attr=x: attr - self.add_message( - "used-before-assignment", - args=node.name, - node=node, - ) - else: - self.add_message( - "undefined-variable", args=node.name, node=node - ) - return (VariableVisitConsumerAction.CONSUME, found_nodes) + # We check lineno because doing the following is fine: + # class A: + # x = 42 + # y = lambda attr: x + attr + if ( + isinstance(frame, nodes.ClassDef) + and node.name in frame.locals + and stmt.fromlineno <= defstmt.fromlineno + ): + self.add_message( + "used-before-assignment", args=node.name, node=node + ) + elif current_consumer.scope_type == "lambda": self.add_message("undefined-variable", args=node.name, node=node) return (VariableVisitConsumerAction.CONSUME, found_nodes) |