mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
+11
@@ -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));
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
def f(x=(<error descr="'yield' outside of function">yield 10</error>)):
|
||||
return x
|
||||
@@ -0,0 +1 @@
|
||||
g = lambda: (yield 10)
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user