Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also check Lambda for await-outside-async #9653

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/9653.false_negative
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a false positive for `await-outside-async` when await is inside Lambda.

Refs #9653
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
Loading