From 482f3f520881b3891bf80371c54db4b4875f85e1 Mon Sep 17 00:00:00 2001 From: Tianyu Chen Date: Sun, 19 May 2024 20:13:00 +0800 Subject: [PATCH] Also check Lambda for await-outside-async --- pylint/checkers/typecheck.py | 2 +- tests/functional/a/await_outside_async.py | 4 ++++ tests/functional/a/await_outside_async.txt | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 56bd729c18..ed79294153 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -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) diff --git a/tests/functional/a/await_outside_async.py b/tests/functional/a/await_outside_async.py index 2bc1267615..1e18169a53 100644 --- a/tests/functional/a/await_outside_async.py +++ b/tests/functional/a/await_outside_async.py @@ -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] diff --git a/tests/functional/a/await_outside_async.txt b/tests/functional/a/await_outside_async.txt index 554eeccb24..8edd4e5cdc 100644 --- a/tests/functional/a/await_outside_async.txt +++ b/tests/functional/a/await_outside_async.txt @@ -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.:'await' should be used within an async function:UNDEFINED