From 315adba906b23fd745b8e66293f0128e77bd030b Mon Sep 17 00:00:00 2001 From: GiGaGon <107241144+MeGaGiGaGon@users.noreply.github.com> Date: Sat, 28 Jun 2025 08:15:34 -0700 Subject: [PATCH] [`flake8-async`] Make `ASYNC251` example error out-of-the-box (#18990) ## Summary Part of #18972 This PR makes [blocking-sleep-in-async-function (ASYNC251)](https://docs.astral.sh/ruff/rules/blocking-sleep-in-async-function/#blocking-sleep-in-async-function-async251)'s example error out-of-the-box [Old example](https://play.ruff.rs/796684a2-c437-4390-b754-491e576ffe5e) ```py async def fetch(): time.sleep(1) ``` [New example](https://play.ruff.rs/90741192-fd0d-49fb-a04e-3127312da659) ```py import time async def fetch(): time.sleep(1) ``` Imports were also added to the `Use instead:` section to make it valid code out-of-the-box. ## Test Plan N/A, no functionality/tests affected --- .../src/rules/flake8_async/rules/blocking_sleep.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_sleep.rs b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_sleep.rs index 10db6b92d2..a3ef530bc0 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_sleep.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_sleep.rs @@ -19,12 +19,18 @@ use crate::checkers::ast::Checker; /// /// ## Example /// ```python +/// import time +/// +/// /// async def fetch(): /// time.sleep(1) /// ``` /// /// Use instead: /// ```python +/// import asyncio +/// +/// /// async def fetch(): /// await asyncio.sleep(1) /// ```