Skip to content

Commit

Permalink
Also check Lambda for await-outside-async
Browse files Browse the repository at this point in the history
  • Loading branch information
UTsweetyfish committed May 19, 2024
1 parent 978981d commit 482f3f5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -2197,7 +2197,7 @@ def _check_await_outside_coroutine(self, node: nodes.Await) -> None:
while not isinstance(node_scope, nodes.Module):
if isinstance(node_scope, nodes.AsyncFunctionDef):
return
if isinstance(node_scope, nodes.FunctionDef):
if isinstance(node_scope, (nodes.FunctionDef, nodes.Lambda)):
break
node_scope = node_scope.parent.scope()
self.add_message("await-outside-async", node=node)
Expand Down
4 changes: 4 additions & 0 deletions tests/functional/a/await_outside_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ def inner_func():
def outer_func():
async def inner_func():
await asyncio.sleep(1)

# pylint: disable=unnecessary-lambda-assignment
async def func3():
f = lambda: await nested() # [await-outside-async]
1 change: 1 addition & 0 deletions tests/functional/a/await_outside_async.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
await-outside-async:12:10:12:24:not_async:'await' should be used within an async function:UNDEFINED
await-outside-async:25:8:25:30:func2.inner_func:'await' should be used within an async function:UNDEFINED
await-outside-async:34:16:34:30:func3.<lambda>:'await' should be used within an async function:UNDEFINED

0 comments on commit 482f3f5

Please sign in to comment.