summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2023-01-12 11:26:28 -0500
committerGitHub <noreply@github.com>2023-01-12 11:26:28 -0500
commite9324649874a7124a08c3826d4cf78a4dc3aa32c (patch)
treebaf150fcf88fc0103fb9c740a651fae024c18881
parent33bbb8266420e34a93ea74299177c19fd463acc0 (diff)
downloadpyflakes-e9324649874a7124a08c3826d4cf78a4dc3aa32c.tar.gz
produce an error when a definition shadows an unused assignment (#761)
-rw-r--r--pyflakes/checker.py5
-rw-r--r--pyflakes/test/test_other.py6
2 files changed, 11 insertions, 0 deletions
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