diff --git a/python/src/com/jetbrains/python/validation/ReturnAnnotator.java b/python/src/com/jetbrains/python/validation/ReturnAnnotator.java
index e0057e02f192..f665bcf8893a 100644
--- a/python/src/com/jetbrains/python/validation/ReturnAnnotator.java
+++ b/python/src/com/jetbrains/python/validation/ReturnAnnotator.java
@@ -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");
+ }
}
}
diff --git a/python/testData/highlighting/yieldInsideAsyncDef.py b/python/testData/highlighting/yieldInsideAsyncDef.py
new file mode 100644
index 000000000000..0b4b8f47aac4
--- /dev/null
+++ b/python/testData/highlighting/yieldInsideAsyncDef.py
@@ -0,0 +1,5 @@
+async def foo(x):
+ await x
+ yield x
+ yield from x
+ return x
diff --git a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java
index 3095bda21611..d0d4e894ea23 100644
--- a/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java
+++ b/python/testSrc/com/jetbrains/python/PythonHighlightingTest.java
@@ -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);