Replace async_timeout.timeout() with asyncio.timeout()
ProprietaryRewrite async with async_timeout.timeout(...) and timeout_at(...) as asyncio.timeout(...) and asyncio.timeout_at(...), which need Python 3.11 or later. Only run it on projects that require 3.11, or as part of org.openrewrite.python.migrate.UpgradeToPython311. A loop= argument, which asyncio does not take, is dropped where it has no side effects, and a value passed as delay= or timeout= is passed positionally. Where the timeout is bound with as, the members asyncio.Timeout spells differently are rewritten in the function that binds it: expired becomes expired(), deadline becomes when(), reject() becomes reschedule(None) and update(t) becomes reschedule(t). A synchronous with directly in an async def, which async-timeout 4 enters and exits as it does async with and 5 no longer supports, becomes async with. Left untouched: a synchronous with anywhere else or entering another context manager too, a timeout built apart from its with, a bound timeout that is shifted, passed elsewhere or whose name is bound again, and a call holding a comment.
org. openrewrite. python. migrate. ReplaceAsyncTimeoutWithAsynciomod run . --recipe= org. openrewrite. python. migrate. ReplaceAsyncTimeoutWithAsyncioInstall it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.