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)); diff --git a/python/src/com/jetbrains/python/validation/ReturnAnnotator.java b/python/src/com/jetbrains/python/validation/ReturnAnnotator.java index 93a877b9aebb..b23cb8c709ba 100644 --- a/python/src/com/jetbrains/python/validation/ReturnAnnotator.java +++ b/python/src/com/jetbrains/python/validation/ReturnAnnotator.java @@ -16,28 +16,25 @@ 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.*; /** - * 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; } } 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 || owner instanceof PyLambdaExpression)) { 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"); - } - */ } } 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/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 77246ba93004..e1fa67de63e4 100644 --- a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java @@ -110,6 +110,15 @@ public class PythonHighlightingTest extends PyTestCase { public void testYieldOutsideOfFunction() { doTest(LanguageLevel.PYTHON27, true, true); } + + public void testYieldInDefaultValue() { + doTest(LanguageLevel.PYTHON34, true, false); + } + + // PY-11663 + public void testYieldInLambda() { + doTest(); + } public void testImportStarAtTopLevel() { doTest(true, false);