Skip to content

ASYNC250 false positive for input call wrapped into lambda #23425

@RomanValov

Description

@RomanValov

Summary

Hello,

with the recent updates ruff started to complain on following snippet of code:

import asyncio


async def main() -> None:
    input("sync")
    await asyncio.to_thread(lambda: input("async"))


if __name__ == '__main__':
    asyncio.run(main())
$ ruff check --select=ASYNC250 async.py
ASYNC250 Blocking call to `input()` in async context
 --> async.py:6:5
  |
5 | async def main() -> None:
6 |     input("sync")
  |     ^^^^^
7 |     await asyncio.to_thread(lambda: input("async"))
  |

ASYNC250 Blocking call to `input()` in async context
 --> async.py:7:37
  |
5 | async def main() -> None:
6 |     input("sync")
7 |     await asyncio.to_thread(lambda: input("async"))
  |                                     ^^^^^
  |

Found 2 errors.

for comparison flake8-async passes "async" invocation:

$ flake8 --enable=ASYNC250 async.py
async.py:6:5: ASYNC250 Blocking sync call `input()` in async function. Wrap in `asyncio.loop.run_in_executor`.

Version

ruff 0.15.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions