This rules raises an issue when trio.sleep() or anyio.sleep() is called with a duration greater than 24 hours.
When using trio.sleep() or anyio.sleep() with very long intervals (greater than 24 hours), the intent is usually to wait
indefinitely or for an extremely long period. Both libraries provide dedicated methods specifically designed for this purpose:
trio.sleep_forever() and anyio.sleep_forever().
Using explicit sleep durations greater than 24 hours has several drawbacks:
86400 * 365 doesn’t clearly communicate that the code intends to wait
indefinitely. In summary, using sleep_forever() is preferable when the intent is to sleep indefinitely as it clearly conveys this purpose, avoiding
maintainability issues caused by using arbitrarily large sleep durations.
Replace calls to trio.sleep() that use intervals greater than 24 hours with calls to trio.sleep_forever().
If the intention is truly to wait for a specific long duration rather than indefinitely, consider expressing that intent more clearly by using named variables or constants.
import trio
async def long_wait():
await trio.sleep(86400 * 365) # Noncompliant
import trio
async def long_wait():
await trio.sleep_forever()
Replace calls to anyio.sleep() that use intervals greater than 24 hours with calls to anyio.sleep_forever().
If the intention is truly to wait for a specific long duration rather than indefinitely, consider expressing that intent more clearly by using named variables or constants.
import anyio
async def long_wait():
await anyio.sleep(86400 * 30) # Noncompliant
import anyio
async def long_wait():
await anyio.sleep_forever()