degenbot.utils.tasks ==================== .. py:module:: degenbot.utils.tasks .. autoapi-nested-parse:: Observing task-reap discipline for cancel-at-teardown paths. Module Contents --------------- .. py:function:: cancel_and_reap(task: asyncio.Task[Any]) -> None :async: Cancel ``task``, await its unwind, and OBSERVE the cancellation. The corpus discipline for teardown reaps: ``task.cancel()`` + ``await`` + ``assert cancelled()``. The awaited ``CancelledError`` is absorbed only once the cancel that caused it is this reap's own ``cancel()`` call; a task that ends any other way (absorbed cancellation, natural completion) fails the assertion instead of silently swallowing a lost cancellation. A task error is never suppressed — only the ``CancelledError`` the reap itself requested is absorbed, so a real failure still propagates to the caller.