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):
425425 Return a generator for the assignments which have not been used.
426426 """
427427 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
429431 and not self .usesLocals
430432 and isinstance (binding , Assignment )):
431433 yield name , binding
Original file line number Diff line number Diff line change @@ -94,6 +94,13 @@ def test_importfrom_future(self):
9494 assert binding .source_statement == 'from __future__ import print_function'
9595 assert str (binding ) == '__future__.print_function'
9696
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+
97104
98105class Test (TestCase ):
99106
Original file line number Diff line number Diff line change @@ -1175,6 +1175,16 @@ def a():
11751175 b = 1
11761176 ''' , m .UnusedVariable )
11771177
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+
11781188 def test_unusedVariableAsLocals (self ):
11791189 """
11801190 Using locals() it is perfectly valid to have unused variables
You can’t perform that action at this time.
0 commit comments