From ef0fddb5892707ac0b0a8d95e5050b98ecdbe692 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Tue, 8 Sep 2015 17:13:25 +0300 Subject: [PATCH] Don't highlight 'await' expression statements as having no effect (PY-16094) --- .../inspections/PyStatementEffectInspection.java | 5 +++++ .../PyStatementEffectInspection/await.py | 8 ++++++++ .../PyStatementEffectInspectionTest.java | 14 ++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 python/testData/inspections/PyStatementEffectInspection/await.py diff --git a/python/src/com/jetbrains/python/inspections/PyStatementEffectInspection.java b/python/src/com/jetbrains/python/inspections/PyStatementEffectInspection.java index f5a087ffa21b..b0d8896c48e8 100644 --- a/python/src/com/jetbrains/python/inspections/PyStatementEffectInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyStatementEffectInspection.java @@ -21,6 +21,7 @@ import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.ResolveResult; import com.intellij.psi.util.PsiTreeUtil; import com.jetbrains.python.PyBundle; +import com.jetbrains.python.PyTokenTypes; import com.jetbrains.python.inspections.quickfix.StatementEffectFunctionCallQuickFix; import com.jetbrains.python.inspections.quickfix.StatementEffectIntroduceVariableQuickFix; import com.jetbrains.python.psi.*; @@ -149,6 +150,10 @@ public class PyStatementEffectInspection extends PyInspection { } } } + else if (expression instanceof PyPrefixExpression) { + final PyPrefixExpression prefixExpr = (PyPrefixExpression)expression; + return prefixExpr.getOperator() == PyTokenTypes.AWAIT_KEYWORD; + } return false; } } diff --git a/python/testData/inspections/PyStatementEffectInspection/await.py b/python/testData/inspections/PyStatementEffectInspection/await.py new file mode 100644 index 000000000000..213d8c4a2eb0 --- /dev/null +++ b/python/testData/inspections/PyStatementEffectInspection/await.py @@ -0,0 +1,8 @@ +async def f(x): + y = await x + await x + if await x: + pass + f(await x) + x + return await x diff --git a/python/testSrc/com/jetbrains/python/inspections/PyStatementEffectInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyStatementEffectInspectionTest.java index 92588bd40bea..c61ddd5cf081 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyStatementEffectInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyStatementEffectInspectionTest.java @@ -16,6 +16,7 @@ package com.jetbrains.python.inspections; import com.jetbrains.python.fixtures.PyInspectionTestCase; +import com.jetbrains.python.psi.LanguageLevel; import org.jetbrains.annotations.NotNull; /** @@ -26,6 +27,19 @@ public class PyStatementEffectInspectionTest extends PyInspectionTestCase { doTest(); } + public void testAwait() { + doTest(LanguageLevel.PYTHON35); + } + + private void doTest(@NotNull LanguageLevel level) { + runWithLanguageLevel(level, new Runnable() { + @Override + public void run() { + doTest(); + } + }); + } + @NotNull @Override protected Class getInspectionClass() {