-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Description and reproduce
pyright, (and pylance in vscode), does not warn against SyntaxError for the following code:
import asyncio
import random
from collections.abc import Callable
async def async_gen(limit: int = 10):
while True:
if limit <= 0:
return
await asyncio.sleep(rtn := random.random())
yield rtn
limit -= 1
async def run_with_callback[U, T](u: U, callback: Callable[[U], T]) -> T:
await asyncio.sleep(0) # some async ops
return callback(u)
async def test_async_for_in_lambda():
result = await run_with_callback(
async_gen(5),
lambda ag: [x async for x in ag], # <- fails to detect syntax error, raises in runtime
)
print(result)
# def run_with_callback_sync[U, T](u: U, callback: Callable[[U], T]) -> T:
# return callback(u)
#
#
# def test_async_for_in_lambda_sync():
# result = run_with_callback_sync(
# async_gen(5),
# lambda ag: [x async for x in ag], # <- correctly detect syntax error, raises in runtime
# )
# print(result)
if __name__ == "__main__":
asyncio.run(test_async_for_in_lambda())Runtime output:
➜ python /tmp/test.py
File "/tmp/test.py", line 23
lambda ag: [x async for x in ag], # <- fails to detect syntax error, raises in runtime
^^^^^^^^^^^^^^^^^^^^^
SyntaxError: asynchronous comprehension outside of an asynchronous functionpyright output:
➜ pyright /tmp/test.py
0 errors, 0 warnings, 0 informationsRelated versions
pyright:1.1.407pylance:2025.10.4python:Python 3.14.0, conda distributed- OS: should be irrelevant, as this is pure Python
Note
May be this can be related to #9414
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working