asyncio.Timeout.__aexit__ does not handle BaseExceptionGroup #137549
Copy link
Copy link
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
There may be a good reason for this I am not seeing, but in the asyncio.Timeout.__aexit__ handler, the exception group handling seems too narrow:
cpython/Lib/asyncio/timeouts.py
Lines 113 to 119 in 9743d06
| if issubclass(exc_type, exceptions.CancelledError): | |
| raise TimeoutError from exc_val | |
| elif exc_val is not None: | |
| self._insert_timeout_error(exc_val) | |
| if isinstance(exc_val, ExceptionGroup): | |
| for exc in exc_val.exceptions: | |
| self._insert_timeout_error(exc) |
Given exc_val itself can be a BaseException and _insert_timeout_error takes a BaseException as an argument, I fail to see a reason not to check for superclass BaseExceptionGroup instead.
cpython/Lib/asyncio/timeouts.py
Line 133 in 9743d06
| def _insert_timeout_error(exc_val: BaseException) -> None: |
This no longer impacts me as I implemented what I was aiming for in a better way, but it still looks like a bug. Is it?
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
- gh-137549: Modify object to BaseExceptionGroup in asyncio.Timeout #137797
- gh-137549: Handle BaseExceptionGroup in asyncio.Timeout.__aexit__ #160957
- [3.15] gh-137549: Handle BaseExceptionGroup in asyncio.Timeout.__aexit__ (GH-160957) #160960
- [3.14] gh-137549: Handle BaseExceptionGroup in asyncio.Timeout.__aexit__ (GH-160957) #160961
Metadata
Metadata
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsDone
Activity
gunyu1019 commentedon Aug 15, 2025
@corona10, Let me try to fix this issue.
corona10 commentedon Aug 15, 2025
Please go ahead!
pythongh-137549: handle BaseExceptionGroup in asyncio.Timeout.__aexit__
Add axis 2: complete classification of all 73 open topic-asyncio issues
Export wave-2 asyncio patches (pythongh-130141 revived + tested, pyth…
gh-137549: Handle BaseExceptionGroup in asyncio.Timeout.__aexit__ (#1…
[3.15] gh-137549: Handle BaseExceptionGroup in asyncio.Timeout.__aexi…
[3.14] gh-137549: Handle BaseExceptionGroup in asyncio.Timeout.__aexi…
asvetlov commentedon Oct 30, 2026
Fixed