Skip to content

Commit

Permalink
chore: added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
josetapadas committed Nov 13, 2024
1 parent 7757cbc commit 271b94d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions test-data/unit/check-async-await.test
Original file line number Diff line number Diff line change
Expand Up @@ -1013,13 +1013,15 @@ async def foo(x: int) -> int: ...

# These are allowed in some cases:
top_level = await foo(1) # E: "await" outside function [top-level-await]
crasher = [await foo(x) for x in [1, 2, 3]] # E: "await" outside function [top-level-await]
crasher = [await foo(x) for x in [1, 2, 3]] # E: "async for" outside async function [syntax] \
# E: "await" outside function [top-level-await]

def bad() -> None:
# These are always critical / syntax issues:
y = [await foo(x) for x in [1, 2, 3]] # E: "await" outside coroutine ("async def") [await-not-async]
y = [await foo(x) for x in [1, 2, 3]] # E: "async for" outside async function [syntax]
async def good() -> None:
y = [await foo(x) for x in [1, 2, 3]] # OK

[builtins fixtures/async_await.pyi]
[typing fixtures/typing-async.pyi]

Expand Down Expand Up @@ -1080,3 +1082,13 @@ class Launcher(P):

[builtins fixtures/async_await.pyi]
[typing fixtures/typing-async.pyi]

[case testAwaitInsideGeneratorExpr]
def foo():
yield 0

def bar():
(await x for x in foo())

[builtins fixtures/async_await.pyi]
[typing fixtures/typing-async.pyi]

0 comments on commit 271b94d

Please sign in to comment.