mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:24 +00:00
Use full arguments range for zero-sleep-call (#8936)
This commit is contained in:
parent
912c39ce2a
commit
46a174a22e
3 changed files with 44 additions and 7 deletions
|
@ -26,5 +26,10 @@ def func():
|
|||
|
||||
from trio import Event, sleep
|
||||
|
||||
|
||||
def func():
|
||||
sleep(0) # TRIO115
|
||||
|
||||
|
||||
async def func():
|
||||
await sleep(seconds=0) # TRIO115
|
||||
|
|
|
@ -16,12 +16,16 @@ use crate::importer::ImportRequest;
|
|||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// import trio
|
||||
///
|
||||
/// async def func():
|
||||
/// await trio.sleep(0)
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// import trio
|
||||
///
|
||||
/// async def func():
|
||||
/// await trio.lowlevel.checkpoint()
|
||||
/// ```
|
||||
|
@ -103,7 +107,7 @@ pub(crate) fn zero_sleep_call(checker: &mut Checker, call: &ExprCall) {
|
|||
)?;
|
||||
let reference_edit =
|
||||
Edit::range_replacement(format!("{binding}.checkpoint"), call.func.range());
|
||||
let arg_edit = Edit::range_deletion(arg.range());
|
||||
let arg_edit = Edit::range_replacement("()".to_string(), call.arguments.range());
|
||||
Ok(Fix::safe_edits(import_edit, [reference_edit, arg_edit]))
|
||||
});
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -85,10 +85,10 @@ TRIO115.py:17:5: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.s
|
|||
19 19 | bar = "bar"
|
||||
20 20 | trio.sleep(bar)
|
||||
|
||||
TRIO115.py:30:5: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.sleep(0)`
|
||||
TRIO115.py:31:5: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.sleep(0)`
|
||||
|
|
||||
29 | def func():
|
||||
30 | sleep(0) # TRIO115
|
||||
30 | def func():
|
||||
31 | sleep(0) # TRIO115
|
||||
| ^^^^^^^^ TRIO115
|
||||
|
|
||||
= help: Replace with `trio.lowlevel.checkpoint()`
|
||||
|
@ -100,8 +100,36 @@ TRIO115.py:30:5: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.s
|
|||
27 |-from trio import Event, sleep
|
||||
27 |+from trio import Event, sleep, lowlevel
|
||||
28 28 |
|
||||
29 29 | def func():
|
||||
30 |- sleep(0) # TRIO115
|
||||
30 |+ lowlevel.checkpoint() # TRIO115
|
||||
29 29 |
|
||||
30 30 | def func():
|
||||
31 |- sleep(0) # TRIO115
|
||||
31 |+ lowlevel.checkpoint() # TRIO115
|
||||
32 32 |
|
||||
33 33 |
|
||||
34 34 | async def func():
|
||||
|
||||
TRIO115.py:35:11: TRIO115 [*] Use `trio.lowlevel.checkpoint()` instead of `trio.sleep(0)`
|
||||
|
|
||||
34 | async def func():
|
||||
35 | await sleep(seconds=0) # TRIO115
|
||||
| ^^^^^^^^^^^^^^^^ TRIO115
|
||||
|
|
||||
= help: Replace with `trio.lowlevel.checkpoint()`
|
||||
|
||||
ℹ Safe fix
|
||||
24 24 | trio.run(trio.sleep(0)) # TRIO115
|
||||
25 25 |
|
||||
26 26 |
|
||||
27 |-from trio import Event, sleep
|
||||
27 |+from trio import Event, sleep, lowlevel
|
||||
28 28 |
|
||||
29 29 |
|
||||
30 30 | def func():
|
||||
--------------------------------------------------------------------------------
|
||||
32 32 |
|
||||
33 33 |
|
||||
34 34 | async def func():
|
||||
35 |- await sleep(seconds=0) # TRIO115
|
||||
35 |+ await lowlevel.checkpoint() # TRIO115
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue