File tree 4 files changed +28
-0
lines changed
4 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,12 @@ Release date: TBA
96
96
97
97
Closes #5360, #3877
98
98
99
+ * Fixed a false positive (affecting unreleased development) for
100
+ ``used-before-assignment`` involving homonyms between filtered comprehensions
101
+ and assignments in except blocks.
102
+
103
+ Closes #5586
104
+
99
105
* Fixed crash with slots assignments and annotated assignments.
100
106
101
107
Closes #5479
Original file line number Diff line number Diff line change @@ -139,6 +139,12 @@ Other Changes
139
139
140
140
Closes #5360, #3877
141
141
142
+ * Fixed a false positive (affecting unreleased development) for
143
+ ``used-before-assignment `` involving homonyms between filtered comprehensions
144
+ and assignments in except blocks.
145
+
146
+ Closes #5586
147
+
142
148
* Fixed crash on list comprehensions that used ``type `` as inner variable name.
143
149
144
150
Closes #5461
Original file line number Diff line number Diff line change @@ -1316,6 +1316,13 @@ def _check_consumer(
1316
1316
if utils .is_func_decorator (current_consumer .node ) or not (
1317
1317
current_consumer .scope_type == "comprehension"
1318
1318
and self ._has_homonym_in_upper_function_scope (node , consumer_level )
1319
+ # But don't catch homonyms against the filter of a comprehension,
1320
+ # (like "if x" in "[x for x in expr() if x]")
1321
+ # https://github.com/PyCQA/pylint/issues/5586
1322
+ and not (
1323
+ isinstance (node .parent .parent , nodes .Comprehension )
1324
+ and node .parent in node .parent .parent .ifs
1325
+ )
1319
1326
):
1320
1327
self ._check_late_binding_closure (node )
1321
1328
self ._loopvar_name (node )
Original file line number Diff line number Diff line change
1
+ """Homonym between filtered comprehension and assignment in except block."""
2
+
3
+ def func ():
4
+ """https://github.com/PyCQA/pylint/issues/5586"""
5
+ try :
6
+ print (value for value in range (1 / 0 ) if isinstance (value , int ))
7
+ except ZeroDivisionError :
8
+ value = 1
9
+ print (value )
You can’t perform that action at this time.
0 commit comments