Skip to content

Commit e932464

Browse files
authored
produce an error when a definition shadows an unused assignment (#761)
1 parent 33bbb82 commit e932464

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pyflakes/checker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ class Definition(Binding):
263263
"""
264264
A binding that defines a function or a class.
265265
"""
266+
def redefines(self, other):
267+
return (
268+
super().redefines(other) or
269+
(isinstance(other, Assignment) and self.name == other.name)
270+
)
266271

267272

268273
class Builtin(Definition):

pyflakes/test/test_other.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ def a(): pass
118118
def a(): pass
119119
''', m.RedefinedWhileUnused)
120120

121+
def test_redefined_function_shadows_variable(self):
122+
self.flakes('''
123+
x = 1
124+
def x(): pass
125+
''', m.RedefinedWhileUnused)
126+
121127
def test_redefinedUnderscoreFunction(self):
122128
"""
123129
Test that shadowing a function definition named with underscore doesn't

0 commit comments

Comments
 (0)