Created
August 6, 2012 19:26
-
-
Save senko/3277784 to your computer and use it in GitHub Desktop.
locals() fix for SublimeLinter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/pyflakes/checker.py b/pyflakes/checker.py | |
index fa2494e..f1eff00 100644 | |
--- a/pyflakes/checker.py | |
+++ b/pyflakes/checker.py | |
@@ -131,6 +131,7 @@ def names(self): | |
class Scope(dict): | |
importStarred = False # set to True when import * is found | |
+ usesLocals = False | |
def __repr__(self): | |
@@ -428,6 +429,10 @@ def NAME(self, node): | |
""" | |
Handle occurrence of Name (which can be a load/store/delete access.) | |
""" | |
+ if node.id == 'locals' and isinstance(node.parent, _ast.Call): | |
+ # we are doing locals() call in current scope | |
+ self.scope.usesLocals = True | |
+ | |
# Locate the name in locals / function / globals scopes. | |
if isinstance(node.ctx, (_ast.Load, _ast.AugLoad)): | |
# try local scope | |
@@ -569,6 +574,7 @@ def checkUnusedAssignments(): | |
""" | |
for name, binding in self.scope.iteritems(): | |
if (not binding.used and not name in self.scope.globals | |
+ and not self.scope.usesLocals | |
and isinstance(binding, Assignment)): | |
self.report(messages.UnusedVariable, | |
binding.source, name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment