mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
[flake8-async] fix detection for large integer sleep durations in ASYNC116
rule (#18767)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
55a2ff91c7
commit
06da2c808f
3 changed files with 47 additions and 8 deletions
|
@ -128,3 +128,11 @@ async def test_trio_async116_helpers():
|
|||
|
||||
await trio.sleep(seconds=86401) # ASYNC116
|
||||
await trio.sleep(delay=86401) # OK
|
||||
|
||||
|
||||
async def _():
|
||||
import trio
|
||||
from trio import sleep
|
||||
|
||||
await sleep(18446744073709551616)
|
||||
await trio.sleep(99999999999999999999)
|
||||
|
|
|
@ -100,14 +100,10 @@ pub(crate) fn long_sleep_not_forever(checker: &Checker, call: &ExprCall) {
|
|||
// TODO(ekohilas): Replace with Duration::from_days(1).as_secs(); when available.
|
||||
let one_day_in_secs = 60 * 60 * 24;
|
||||
match value {
|
||||
Number::Int(int_value) => {
|
||||
let Some(int_value) = int_value.as_u64() else {
|
||||
return;
|
||||
};
|
||||
if int_value <= one_day_in_secs {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Number::Int(int_value) => match int_value.as_u64() {
|
||||
Some(int_value) if int_value <= one_day_in_secs => return,
|
||||
_ => {} // The number is too large, and more than 24 hours
|
||||
},
|
||||
Number::Float(float_value) =>
|
||||
{
|
||||
#[expect(clippy::cast_precision_loss)]
|
||||
|
|
|
@ -330,3 +330,38 @@ ASYNC116.py:129:11: ASYNC116 [*] `trio.sleep()` with >24 hour interval should us
|
|||
129 |- await trio.sleep(seconds=86401) # ASYNC116
|
||||
129 |+ await trio.sleep_forever() # ASYNC116
|
||||
130 130 | await trio.sleep(delay=86401) # OK
|
||||
131 131 |
|
||||
132 132 |
|
||||
|
||||
ASYNC116.py:137:11: ASYNC116 [*] `trio.sleep()` with >24 hour interval should usually be `trio.sleep_forever()`
|
||||
|
|
||||
135 | from trio import sleep
|
||||
136 |
|
||||
137 | await sleep(18446744073709551616)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ASYNC116
|
||||
138 | await trio.sleep(99999999999999999999)
|
||||
|
|
||||
= help: Replace with `trio.sleep_forever()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
134 134 | import trio
|
||||
135 135 | from trio import sleep
|
||||
136 136 |
|
||||
137 |- await sleep(18446744073709551616)
|
||||
137 |+ await trio.sleep_forever()
|
||||
138 138 | await trio.sleep(99999999999999999999)
|
||||
|
||||
ASYNC116.py:138:11: ASYNC116 [*] `trio.sleep()` with >24 hour interval should usually be `trio.sleep_forever()`
|
||||
|
|
||||
137 | await sleep(18446744073709551616)
|
||||
138 | await trio.sleep(99999999999999999999)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ASYNC116
|
||||
|
|
||||
= help: Replace with `trio.sleep_forever()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
135 135 | from trio import sleep
|
||||
136 136 |
|
||||
137 137 | await sleep(18446744073709551616)
|
||||
138 |- await trio.sleep(99999999999999999999)
|
||||
138 |+ await trio.sleep_forever()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue