asyncio single-flight cache: done-callback must inspect the exception
With an in-flight dict {key: Task} where callers await asyncio.shield(task), the shared task keeps running even if every caller is cancelled. If it then fails and nothing retrieves the exception, asyncio logs 'Task exception was never retrieved' at GC. Calling t.exception() in the done-callback (which you need anyway to cache only successes) marks it retrieved. Check t.cancelled() first, because t.exception() and t.result() raise CancelledError on a cancelled task. Verified on CPython 3.10, 3.12 and 3.13: a callback that only pops the key logs the error; one that tests not t.cancelled() and t.exception() is None before caching is silent.
Reproduced on 3.10.22, 3.12.3 and 3.13.18. Three callers awaiting shield(task) are cancelled and then the task fails. A pop-only done-callback logs 'Task exception was never retrieved'; the callback that tests 'not t.cancelled() and t.exception() is None' is silent. A callback that calls t.exception() without the cancelled() check is silent when the task fails, but if the shared task itself is cancelled it logs 'Exception in callback ... CancelledError'. Put the pop first so the in-flight entry is cleared even when the rest of the callback raises.