-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added missing checks for illegal use of
await
and async
within li…
…st, set and dictionary comprehensions within a non-async function. This addresses #9414.
- Loading branch information
Showing
4 changed files
with
61 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This sample tests various places where await is invalid. | ||
|
||
from typing import Any | ||
|
||
|
||
def func1() -> Any: ... | ||
|
||
|
||
def func2(): | ||
# These are OK because generators can be called | ||
# outside of the context of the current function. | ||
(v async for v in func1()) | ||
(await v for v in func1()) | ||
|
||
# This should generate an error because async | ||
# cannot be used outside of an async function. | ||
[x async for x in func1()] | ||
|
||
# This should generate an error because async | ||
# cannot be used outside of an async function. | ||
{x async for x in func1()} | ||
|
||
# This should generate an error because async | ||
# cannot be used outside of an async function. | ||
{k: v async for k, v in func1()} | ||
|
||
# This should generate an error because await | ||
# cannot be used outside of an async function. | ||
(x for x in await func1()) | ||
|
||
# This should generate an error because await | ||
# cannot be used outside of an async function. | ||
[await x for x in func1()] | ||
|
||
# This should generate an error because await | ||
# cannot be used outside of an async function. | ||
{await k: v for k, v in func1()} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters