Skip to content

Commit adf0535

Browse files
authored
Also check Lambda for await-outside-async (#9653)
1 parent 032ab32 commit adf0535

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a false positive for `await-outside-async` when await is inside Lambda.
2+
3+
Refs #9653

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)