Skip to content

Instantly share code, notes, and snippets.

@senko
Created August 6, 2012 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senko/3277784 to your computer and use it in GitHub Desktop.
Save senko/3277784 to your computer and use it in GitHub Desktop.
locals() fix for SublimeLinter
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