Skip to content

Commit

Permalink
produce an error when a definition shadows an unused assignment (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile authored Jan 12, 2023
1 parent 33bbb82 commit e932464
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pyflakes/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ class Definition(Binding):
"""
A binding that defines a function or a class.
"""
def redefines(self, other):
return (
super().redefines(other) or
(isinstance(other, Assignment) and self.name == other.name)
)


class Builtin(Definition):
Expand Down
6 changes: 6 additions & 0 deletions pyflakes/test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ def a(): pass
def a(): pass
''', m.RedefinedWhileUnused)

def test_redefined_function_shadows_variable(self):
self.flakes('''
x = 1
def x(): pass
''', m.RedefinedWhileUnused)

def test_redefinedUnderscoreFunction(self):
"""
Test that shadowing a function definition named with underscore doesn't
Expand Down

0 comments on commit e932464

Please sign in to comment.