diff --git a/python/src/com/jetbrains/python/inspections/PyUnusedLocalVariableInspectionVisitor.java b/python/src/com/jetbrains/python/inspections/PyUnusedLocalVariableInspectionVisitor.java index 64a6f9a77505..7bafad36f792 100644 --- a/python/src/com/jetbrains/python/inspections/PyUnusedLocalVariableInspectionVisitor.java +++ b/python/src/com/jetbrains/python/inspections/PyUnusedLocalVariableInspectionVisitor.java @@ -53,10 +53,26 @@ class PyUnusedLocalVariableInspectionVisitor extends PyInspectionVisitor { registerProblems(); } + class DontPerformException extends RuntimeException {} private void processScope(final ScopeOwner owner) { // TODO[oleg] Do not show warning in python code expression mode (evaluate in debug or watches) + // Do not perform inspection if locals() call is found + try { + owner.accept(new PyRecursiveElementVisitor(){ + @Override + public void visitPyCallExpression(final PyCallExpression node) { + if ("locals".equals(node.getCallee().getText())){ + throw new DontPerformException(); + } + } + }); + } + catch (DontPerformException e) { + return; + } + // If method overrides others do not mark parameters as unused if they are boolean parametersCanBeUnused = false; if (owner instanceof PyFunction) {