File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -425,7 +425,9 @@ def unusedAssignments(self):
425
425
Return a generator for the assignments which have not been used.
426
426
"""
427
427
for name , binding in self .items ():
428
- if (not binding .used and name not in self .globals
428
+ if (not binding .used
429
+ and name != '_' # see issue #202
430
+ and name not in self .globals
429
431
and not self .usesLocals
430
432
and isinstance (binding , Assignment )):
431
433
yield name , binding
Original file line number Diff line number Diff line change @@ -94,6 +94,13 @@ def test_importfrom_future(self):
94
94
assert binding .source_statement == 'from __future__ import print_function'
95
95
assert str (binding ) == '__future__.print_function'
96
96
97
+ def test_unusedImport_underscore (self ):
98
+ """
99
+ The magic underscore var should be reported as unused when used as an
100
+ import alias.
101
+ """
102
+ self .flakes ('import fu as _' , m .UnusedImport )
103
+
97
104
98
105
class Test (TestCase ):
99
106
Original file line number Diff line number Diff line change @@ -1175,6 +1175,16 @@ def a():
1175
1175
b = 1
1176
1176
''' , m .UnusedVariable )
1177
1177
1178
+ def test_unusedUnderscoreVariable (self ):
1179
+ """
1180
+ Don't warn when the magic "_" (underscore) variable is unused.
1181
+ See issue #202.
1182
+ """
1183
+ self .flakes ('''
1184
+ def a(unused_param):
1185
+ _ = unused_param
1186
+ ''' )
1187
+
1178
1188
def test_unusedVariableAsLocals (self ):
1179
1189
"""
1180
1190
Using locals() it is perfectly valid to have unused variables
You can’t perform that action at this time.
0 commit comments