summaryrefslogtreecommitdiff
path: root/pyflakes/checker.py
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2013-03-30 23:23:54 +0100
committerFlorent Xicluna <florent.xicluna@gmail.com>2013-03-30 23:23:54 +0100
commit727d7f8285dc7d7b411063bdc4bafb07d0552723 (patch)
tree00aba43d7cf7ef42b17dcdd744f8f3bd3afccce1 /pyflakes/checker.py
parent81279a1353754e4d6616f88cbb6373acb5740862 (diff)
downloadpyflakes-727d7f8285dc7d7b411063bdc4bafb07d0552723.tar.gz
Support special locals like __tracebackhide__ for py.test.
Diffstat (limited to 'pyflakes/checker.py')
-rw-r--r--pyflakes/checker.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 5d1f681..e023542 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -172,10 +172,22 @@ class FunctionScope(Scope):
@ivar globals: Names declared 'global' in this function.
"""
usesLocals = False
+ alwaysUsed = set(['__tracebackhide__'])
def __init__(self):
super(FunctionScope, self).__init__()
- self.globals = set()
+ # Simplify: manage the special locals as globals
+ self.globals = self.alwaysUsed.copy()
+
+ def unusedAssignments(self):
+ """
+ Return a generator for the assignments which have not been used.
+ """
+ for name, binding in self.items():
+ if (not binding.used and name not in self.globals
+ and not self.usesLocals
+ and isinstance(binding, Assignment)):
+ yield name, binding
class ModuleScope(Scope):
@@ -682,12 +694,9 @@ class Checker(object):
"""
Check to see if any assignments have not been used.
"""
- for name, binding in self.scope.items():
- if (not binding.used and name not in self.scope.globals
- and not self.scope.usesLocals
- and isinstance(binding, Assignment)):
- self.report(messages.UnusedVariable,
- binding.source.lineno, name)
+ for name, binding in self.scope.unusedAssignments():
+ self.report(messages.UnusedVariable,
+ binding.source.lineno, name)
self.deferAssignment(checkUnusedAssignments)
self.popScope()