Skip to content

Commit 482f3f5

Browse files
committed
Also check Lambda for await-outside-async
1 parent 978981d commit 482f3f5

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

pylint/checkers/typecheck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2197,7 +2197,7 @@ def _check_await_outside_coroutine(self, node: nodes.Await) -> None:
21972197
while not isinstance(node_scope, nodes.Module):
21982198
if isinstance(node_scope, nodes.AsyncFunctionDef):
21992199
return
2200-
if isinstance(node_scope, nodes.FunctionDef):
2200+
if isinstance(node_scope, (nodes.FunctionDef, nodes.Lambda)):
22012201
break
22022202
node_scope = node_scope.parent.scope()
22032203
self.add_message("await-outside-async", node=node)

tests/functional/a/await_outside_async.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ def inner_func():
2828
def outer_func():
2929
async def inner_func():
3030
await asyncio.sleep(1)
31+
32+
# pylint: disable=unnecessary-lambda-assignment
33+
async def func3():
34+
f = lambda: await nested() # [await-outside-async]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
await-outside-async:12:10:12:24:not_async:'await' should be used within an async function:UNDEFINED
22
await-outside-async:25:8:25:30:func2.inner_func:'await' should be used within an async function:UNDEFINED
3+
await-outside-async:34:16:34:30:func3.<lambda>:'await' should be used within an async function:UNDEFINED

0 commit comments

Comments
 (0)