File tree Expand file tree Collapse file tree 4 files changed +21
-4
lines changed
tests/functional/u/undefined Expand file tree Collapse file tree 4 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,11 @@ Release date: TBA
50
50
51
51
* ``used-before-assignment`` now checks names in try blocks.
52
52
53
+ * Fixed false positive with ``used-before-assignment`` for assignment expressions
54
+ in lambda statements.
55
+
56
+ Closes #5360, #3877
57
+
53
58
* Some files in ``pylint.testutils`` were deprecated. In the future imports should be done from the
54
59
``pylint.testutils.functional`` namespace directly.
55
60
Original file line number Diff line number Diff line change @@ -86,6 +86,11 @@ Other Changes
86
86
87
87
* ``used-before-assignment `` now checks names in try blocks.
88
88
89
+ * Fixed false positive with ``used-before-assignment `` for assignment expressions
90
+ in lambda statements.
91
+
92
+ Closes #5360, #3877
93
+
89
94
* Require Python ``3.6.2 `` to run pylint.
90
95
91
96
Closes #5065
Original file line number Diff line number Diff line change @@ -1402,10 +1402,6 @@ def _check_consumer(
1402
1402
"used-before-assignment" , args = node .name , node = node
1403
1403
)
1404
1404
1405
- elif current_consumer .scope_type == "lambda" :
1406
- self .add_message ("undefined-variable" , args = node .name , node = node )
1407
- return (VariableVisitConsumerAction .CONSUME , found_nodes )
1408
-
1409
1405
elif self ._is_only_type_assignment (node , defstmt ):
1410
1406
self .add_message ("undefined-variable" , args = node .name , node = node )
1411
1407
return (VariableVisitConsumerAction .CONSUME , found_nodes )
Original file line number Diff line number Diff line change @@ -97,3 +97,14 @@ def no_parameters_in_function_default() -> None:
97
97
COMPREHENSION_FIVE = {i : (else_assign_2 := i ) if False else 0 for i in range (10 )}
98
98
99
99
print (else_assign_2 ) # [undefined-variable]
100
+
101
+
102
+ # Tests for assignment expressions in lambda statements
103
+
104
+ things = []
105
+ sorted_things = sorted (
106
+ things ,
107
+ key = lambda thing : x_0
108
+ if (x_0 := thing .this_value ) < (x_1 := thing .that_value )
109
+ else x_1 ,
110
+ )
You can’t perform that action at this time.
0 commit comments