From fcf665e7618067f3fc06df677c9201bb1b14c233 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Tue, 23 Apr 2024 12:41:27 +0300 Subject: [PATCH] PY-64304 EA-247016 Report illegal usages of "await" expressions even if there is no operand In other words, in a statement like "await = 42" there are now both a warning about the missing operand and a warning that an await expression cannot be used as an assignment target. This behavior is consistent with other expressions where additional parsing errors are not special-cased. GitOrigin-RevId: 37a68eacc7ec042435c185f9ddd8bc2eea42b40f --- .../python/validation/AssignTargetAnnotator.java | 2 +- .../highlighting/asyncAndAwaitAsIdentifiersIn37.py | 2 +- python/testData/highlighting/awaitInDictPy36.py | 10 +++++----- python/testData/highlighting/awaitInGenerator.py | 6 +++--- python/testData/highlighting/awaitInListPy36.py | 10 +++++----- python/testData/highlighting/awaitInSetPy36.py | 10 +++++----- python/testData/highlighting/awaitInTuple.py | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/python/python-psi-impl/src/com/jetbrains/python/validation/AssignTargetAnnotator.java b/python/python-psi-impl/src/com/jetbrains/python/validation/AssignTargetAnnotator.java index 1fcde48c7567..33ddcaac53c6 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/validation/AssignTargetAnnotator.java +++ b/python/python-psi-impl/src/com/jetbrains/python/validation/AssignTargetAnnotator.java @@ -299,7 +299,7 @@ public class AssignTargetAnnotator extends PyAnnotator { @Override public void visitPyPrefixExpression(@NotNull PyPrefixExpression node) { - if (node.getOperator() == PyTokenTypes.AWAIT_KEYWORD && node.getOperand() != null) { + if (node.getOperator() == PyTokenTypes.AWAIT_KEYWORD) { getHolder().newAnnotation(HighlightSeverity.ERROR, message("ANN.cant.assign.to.await.expr")).range(node).create(); } } diff --git a/python/testData/highlighting/asyncAndAwaitAsIdentifiersIn37.py b/python/testData/highlighting/asyncAndAwaitAsIdentifiersIn37.py index 6eceb6b295ff..b214b7c4381e 100644 --- a/python/testData/highlighting/asyncAndAwaitAsIdentifiersIn37.py +++ b/python/testData/highlighting/asyncAndAwaitAsIdentifiersIn37.py @@ -17,4 +17,4 @@ def await(): pass -await = 10 \ No newline at end of file +await = 10 \ No newline at end of file diff --git a/python/testData/highlighting/awaitInDictPy36.py b/python/testData/highlighting/awaitInDictPy36.py index c26ac3d90f07..fa1aaa5b9fd5 100644 --- a/python/testData/highlighting/awaitInDictPy36.py +++ b/python/testData/highlighting/awaitInDictPy36.py @@ -1,5 +1,5 @@ async def f11(x): - y = {await: 10 for await in []} # fail + y = {await: 10 for await in []} # fail await x @@ -9,7 +9,7 @@ def f12(x): async def f21(x): - y = {mapper(await): 10 for await in []} # fail + y = {mapper(await): 10 for await in []} # fail await x @@ -19,7 +19,7 @@ def f22(x): async def f31(x): - await = [] # fail + await = [] # fail y = {i: 10 for i in await} # fail await x @@ -51,7 +51,7 @@ async def f44(x): async def f51(): - await = 5 # fail + await = 5 # fail return {await: 10} # fail @@ -61,7 +61,7 @@ def f52(): async def f61(): - await = 5 # fail + await = 5 # fail return {"a": 10, await: 10, "b": 10} # fail diff --git a/python/testData/highlighting/awaitInGenerator.py b/python/testData/highlighting/awaitInGenerator.py index b9a044730548..af0538f6f3b7 100644 --- a/python/testData/highlighting/awaitInGenerator.py +++ b/python/testData/highlighting/awaitInGenerator.py @@ -1,5 +1,5 @@ async def f11(x): - y = (await for await in []) # fail + y = (await for await in []) # fail await x @@ -9,7 +9,7 @@ def f12(x): async def f21(x): - y = (mapper(await) for await in []) # fail + y = (mapper(await) for await in []) # fail await x @@ -19,7 +19,7 @@ def f22(x): async def f31(x): - await = [] # fail + await = [] # fail y = (i for i in await) # fail await x diff --git a/python/testData/highlighting/awaitInListPy36.py b/python/testData/highlighting/awaitInListPy36.py index 56cd6293a2e0..12f906f4622b 100644 --- a/python/testData/highlighting/awaitInListPy36.py +++ b/python/testData/highlighting/awaitInListPy36.py @@ -1,5 +1,5 @@ async def f11(x): - y = [await for await in []] # fail + y = [await for await in []] # fail await x @@ -9,7 +9,7 @@ def f12(x): async def f21(x): - y = [mapper(await) for await in []] # fail + y = [mapper(await) for await in []] # fail await x @@ -19,7 +19,7 @@ def f22(x): async def f31(x): - await = [] # fail + await = [] # fail y = [i for i in await] # fail await x @@ -51,7 +51,7 @@ async def f44(x): async def f51(): - await = 5 # fail + await = 5 # fail return [await] # fail @@ -61,7 +61,7 @@ def f52(): async def f61(): - await = 5 # fail + await = 5 # fail return ["a", await, "b"] # fail diff --git a/python/testData/highlighting/awaitInSetPy36.py b/python/testData/highlighting/awaitInSetPy36.py index a19fdf082af7..b907389dec7d 100644 --- a/python/testData/highlighting/awaitInSetPy36.py +++ b/python/testData/highlighting/awaitInSetPy36.py @@ -1,5 +1,5 @@ async def f11(x): - y = {await for await in []} # fail + y = {await for await in []} # fail await x @@ -9,7 +9,7 @@ def f12(x): async def f21(x): - y = {mapper(await) for await in []} # fail + y = {mapper(await) for await in []} # fail await x @@ -19,7 +19,7 @@ def f22(x): async def f31(x): - await = [] # fail + await = [] # fail y = {i for i in await} # fail await x @@ -51,7 +51,7 @@ async def f44(x): async def f51(): - await = 5 # fail + await = 5 # fail return {await} # fail @@ -61,7 +61,7 @@ def f52(): async def f61(): - await = 5 # fail + await = 5 # fail return {"a", await, "b"} # fail diff --git a/python/testData/highlighting/awaitInTuple.py b/python/testData/highlighting/awaitInTuple.py index 006c6797d07f..dc2f352e1f73 100644 --- a/python/testData/highlighting/awaitInTuple.py +++ b/python/testData/highlighting/awaitInTuple.py @@ -1,5 +1,5 @@ async def f51(): - await = 5 # fail + await = 5 # fail return (await) # fail @@ -9,7 +9,7 @@ def f52(): async def f61(): - await = 5 # fail + await = 5 # fail return ("a", await, "b") # fail