From e9324649874a7124a08c3826d4cf78a4dc3aa32c Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 12 Jan 2023 11:26:28 -0500 Subject: produce an error when a definition shadows an unused assignment (#761) --- pyflakes/checker.py | 5 +++++ pyflakes/test/test_other.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/pyflakes/checker.py b/pyflakes/checker.py index e927715..4d778a8 100644 --- a/pyflakes/checker.py +++ b/pyflakes/checker.py @@ -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): diff --git a/pyflakes/test/test_other.py b/pyflakes/test/test_other.py index 42e99ae..aebdcea 100644 --- a/pyflakes/test/test_other.py +++ b/pyflakes/test/test_other.py @@ -118,6 +118,12 @@ class Test(TestCase): 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 -- cgit v1.2.1