From 222ecc216c0111b2b639ba9026b1efd87d6e856b Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Fri, 23 May 2014 20:22:21 +0400 Subject: [PATCH 1/4] hide execute in console action if not available --- .../tree/actions/EvaluateInConsoleFromTreeAction.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/actions/EvaluateInConsoleFromTreeAction.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/actions/EvaluateInConsoleFromTreeAction.java index 5bff527452c4..8f515ee5907e 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/actions/EvaluateInConsoleFromTreeAction.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/actions/EvaluateInConsoleFromTreeAction.java @@ -14,6 +14,17 @@ class EvaluateInConsoleFromTreeAction extends XAddToWatchesAction { return super.isEnabled(node, e) && getConsoleExecuteAction(e) != null; } + @Override + public void update(AnActionEvent e) { + if (getConsoleExecuteAction(e) != null) { + e.getPresentation().setVisible(true); + super.update(e); + } + else { + e.getPresentation().setEnabledAndVisible(false); + } + } + @Nullable private static ConsoleExecuteAction getConsoleExecuteAction(@NotNull AnActionEvent e) { return XEvaluateInConsoleFromEditorActionHandler.getConsoleExecuteAction(e.getData(LangDataKeys.CONSOLE_VIEW)); From e23c4c09ac8151ec31e949ff16b7e563bfb49fe8 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Fri, 23 May 2014 20:38:35 +0400 Subject: [PATCH 2/4] Cleanup --- .../com/jetbrains/python/validation/ReturnAnnotator.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/python/src/com/jetbrains/python/validation/ReturnAnnotator.java b/python/src/com/jetbrains/python/validation/ReturnAnnotator.java index 93a877b9aebb..3793e00dd498 100644 --- a/python/src/com/jetbrains/python/validation/ReturnAnnotator.java +++ b/python/src/com/jetbrains/python/validation/ReturnAnnotator.java @@ -19,14 +19,13 @@ import com.intellij.psi.util.PsiTreeUtil; import com.jetbrains.python.psi.*; /** - * Highlights incorrect return statements: 'return' and 'yield' outside functions, returning values from generators; + * Highlights incorrect return statements: 'return' and 'yield' outside functions, returning values from generators. */ public class ReturnAnnotator extends PyAnnotator { public void visitPyReturnStatement(final PyReturnStatement node) { PyFunction function = PsiTreeUtil.getParentOfType(node, PyFunction.class, false, PyClass.class); if (function == null) { getHolder().createErrorAnnotation(node, "'return' outside of function"); - return; } } @@ -34,10 +33,5 @@ public class ReturnAnnotator extends PyAnnotator { if (PsiTreeUtil.getParentOfType(node, PyFunction.class, false, PyClass.class) == null) { getHolder().createErrorAnnotation(node, "'yield' outside of function"); } - /* this is now allowed in python 2.5 - if (node.getContainingElement(PyTryFinallyStatement.class) != null) { - getHolder().createErrorAnnotation(node, "'yield' not allowed in a 'try' block with a 'finally' clause"); - } - */ } } From 5de561b8853f455b7027751291e615194d440512 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Fri, 23 May 2014 20:40:51 +0400 Subject: [PATCH 3/4] Fixed false negative for 'yield' expressions in default values of parameters --- .../src/com/jetbrains/python/validation/ReturnAnnotator.java | 5 ++++- python/testData/highlighting/yieldInDefaultValue.py | 2 ++ .../testSrc/com/jetbrains/python/PythonHighlightingTest.java | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 python/testData/highlighting/yieldInDefaultValue.py diff --git a/python/src/com/jetbrains/python/validation/ReturnAnnotator.java b/python/src/com/jetbrains/python/validation/ReturnAnnotator.java index 3793e00dd498..291051f58568 100644 --- a/python/src/com/jetbrains/python/validation/ReturnAnnotator.java +++ b/python/src/com/jetbrains/python/validation/ReturnAnnotator.java @@ -16,6 +16,8 @@ package com.jetbrains.python.validation; import com.intellij.psi.util.PsiTreeUtil; +import com.jetbrains.python.codeInsight.controlflow.ScopeOwner; +import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil; import com.jetbrains.python.psi.*; /** @@ -30,7 +32,8 @@ public class ReturnAnnotator extends PyAnnotator { } public void visitPyYieldExpression(final PyYieldExpression node) { - if (PsiTreeUtil.getParentOfType(node, PyFunction.class, false, PyClass.class) == null) { + final ScopeOwner owner = ScopeUtil.getScopeOwner(node); + if (!(owner instanceof PyFunction)) { getHolder().createErrorAnnotation(node, "'yield' outside of function"); } } diff --git a/python/testData/highlighting/yieldInDefaultValue.py b/python/testData/highlighting/yieldInDefaultValue.py new file mode 100644 index 000000000000..1d2482c35714 --- /dev/null +++ b/python/testData/highlighting/yieldInDefaultValue.py @@ -0,0 +1,2 @@ +def f(x=(yield 10)): + return x diff --git a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java index 77246ba93004..51fcd30dc896 100644 --- a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java @@ -110,6 +110,10 @@ public class PythonHighlightingTest extends PyTestCase { public void testYieldOutsideOfFunction() { doTest(LanguageLevel.PYTHON27, true, true); } + + public void testYieldInDefaultValue() { + doTest(LanguageLevel.PYTHON34, true, false); + } public void testImportStarAtTopLevel() { doTest(true, false); From 99c6577bd7d3bead9dde310d7a53470e7bea822d Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Fri, 23 May 2014 20:46:56 +0400 Subject: [PATCH 4/4] Fixed false positive for 'yield' expressions in lambdas (PY-11663) --- .../src/com/jetbrains/python/validation/ReturnAnnotator.java | 2 +- python/testData/highlighting/yieldInLambda.py | 1 + .../testSrc/com/jetbrains/python/PythonHighlightingTest.java | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 python/testData/highlighting/yieldInLambda.py diff --git a/python/src/com/jetbrains/python/validation/ReturnAnnotator.java b/python/src/com/jetbrains/python/validation/ReturnAnnotator.java index 291051f58568..b23cb8c709ba 100644 --- a/python/src/com/jetbrains/python/validation/ReturnAnnotator.java +++ b/python/src/com/jetbrains/python/validation/ReturnAnnotator.java @@ -33,7 +33,7 @@ public class ReturnAnnotator extends PyAnnotator { public void visitPyYieldExpression(final PyYieldExpression node) { final ScopeOwner owner = ScopeUtil.getScopeOwner(node); - if (!(owner instanceof PyFunction)) { + if (!(owner instanceof PyFunction || owner instanceof PyLambdaExpression)) { getHolder().createErrorAnnotation(node, "'yield' outside of function"); } } diff --git a/python/testData/highlighting/yieldInLambda.py b/python/testData/highlighting/yieldInLambda.py new file mode 100644 index 000000000000..72ecd04afc2e --- /dev/null +++ b/python/testData/highlighting/yieldInLambda.py @@ -0,0 +1 @@ +g = lambda: (yield 10) diff --git a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java index 51fcd30dc896..e1fa67de63e4 100644 --- a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java @@ -114,6 +114,11 @@ public class PythonHighlightingTest extends PyTestCase { public void testYieldInDefaultValue() { doTest(LanguageLevel.PYTHON34, true, false); } + + // PY-11663 + public void testYieldInLambda() { + doTest(); + } public void testImportStarAtTopLevel() { doTest(true, false);