summaryrefslogtreecommitdiff
path: root/pyflakes/checker.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyflakes/checker.py')
-rw-r--r--pyflakes/checker.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 56fc3ca..89c9d0a 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -588,7 +588,7 @@ class FunctionScope(Scope):
self.returnValue = None # First non-empty return
self.isGenerator = False # Detect a generator
- def unusedAssignments(self):
+ def unused_assignments(self):
"""
Return a generator for the assignments which have not been used.
"""
@@ -600,6 +600,14 @@ class FunctionScope(Scope):
isinstance(binding, Assignment)):
yield name, binding
+ def unused_annotations(self):
+ """
+ Return a generator for the annotations which have not been used.
+ """
+ for name, binding in self.items():
+ if not binding.used and isinstance(binding, Annotation):
+ yield name, binding
+
class GeneratorScope(Scope):
pass
@@ -1156,6 +1164,7 @@ class Checker:
binding = scope.get(name, None)
if isinstance(binding, Annotation) and not self._in_postponed_annotation:
+ scope[name].used = True
continue
if name == 'print' and isinstance(binding, Builtin):
@@ -2084,13 +2093,22 @@ class Checker:
self.handleChildren(node, omit=['decorator_list', 'returns'])
- def checkUnusedAssignments():
+ def check_unused_assignments():
"""
Check to see if any assignments have not been used.
"""
- for name, binding in self.scope.unusedAssignments():
+ for name, binding in self.scope.unused_assignments():
self.report(messages.UnusedVariable, binding.source, name)
- self.deferAssignment(checkUnusedAssignments)
+
+ def check_unused_annotations():
+ """
+ Check to see if any annotations have not been used.
+ """
+ for name, binding in self.scope.unused_annotations():
+ self.report(messages.UnusedAnnotation, binding.source, name)
+
+ self.deferAssignment(check_unused_assignments)
+ self.deferAssignment(check_unused_annotations)
self.popScope()