mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Annotate 'yield' inside async functions as errors (PY-16094)
This commit is contained in:
@@ -21,7 +21,7 @@ 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, 'yield' inside async functions.
|
||||
*/
|
||||
public class ReturnAnnotator extends PyAnnotator {
|
||||
public void visitPyReturnStatement(final PyReturnStatement node) {
|
||||
@@ -36,5 +36,8 @@ public class ReturnAnnotator extends PyAnnotator {
|
||||
if (!(owner instanceof PyFunction || owner instanceof PyLambdaExpression)) {
|
||||
getHolder().createErrorAnnotation(node, "'yield' outside of function");
|
||||
}
|
||||
if (owner instanceof PyFunction && ((PyFunction)owner).isAsync()) {
|
||||
getHolder().createErrorAnnotation(node, "'yield' inside async function");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
async def foo(x):
|
||||
await x
|
||||
<error descr="'yield' inside async function">yield x</error>
|
||||
<error descr="'yield' inside async function">yield from x</error>
|
||||
return x
|
||||
@@ -237,6 +237,10 @@ public class PythonHighlightingTest extends PyTestCase {
|
||||
doTest(LanguageLevel.PYTHON35, true, true);
|
||||
}
|
||||
|
||||
public void testYieldInsideAsyncDef() {
|
||||
doTest(LanguageLevel.PYTHON35, false, false);
|
||||
}
|
||||
|
||||
// ---
|
||||
private void doTest(final LanguageLevel languageLevel, final boolean checkWarnings, final boolean checkInfos) {
|
||||
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), languageLevel);
|
||||
|
||||
Reference in New Issue
Block a user