Skip to content

gh-137549: Handle BaseExceptionGroup in asyncio.Timeout.__aexit__ - #160957

Merged
asvetlov merged 1 commit into
python:mainfrom
asvetlov:claude/cpython-137549-fix-623cc5
Oct 30, 2026
Merged

asvetlov merged 1 commit into
python:mainfrom
asvetlov:claude/cpython-137549-fix-623cc5

Conversation

@asvetlov

Copy link
Copy Markdown
Contributor

asyncio.timeout() inserts a TimeoutError into the context chain of the sub-exceptions of an ExceptionGroup, but skipped BaseExceptionGroup. That happens, for example, when a TaskGroup task raises a BaseException subclass other than SystemExit/KeyboardInterrupt during cancellation; its sub-exception kept a bare CancelledError as its __context__.

The check now uses BaseExceptionGroup (a superclass of ExceptionGroup, so existing behaviour is unchanged). Added a regression test mirroring test_timeout_taskgroup.

🤖 Generated with Claude Code

asyncio.timeout() inserted TimeoutError into the context chain of
sub-exceptions only for ExceptionGroup; do the same for
BaseExceptionGroup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@asvetlov
asvetlov merged commit a683f70 into python:main Oct 30, 2026
65 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @asvetlov for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 30, 2026

Copy link
Copy Markdown

GH-160960 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 30, 2026
@bedevere-app

bedevere-app Bot commented Oct 30, 2026

Copy link
Copy Markdown

GH-160961 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 30, 2026
asvetlov added a commit that referenced this pull request Oct 30, 2026
…t__ (GH-160957) (#160960)

gh-137549: Handle BaseExceptionGroup in asyncio.Timeout.__aexit__ (GH-160957)

asyncio.timeout() inserted TimeoutError into the context chain of
sub-exceptions only for ExceptionGroup; do the same for
BaseExceptionGroup.
(cherry picked from commit a683f70)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
asvetlov added a commit that referenced this pull request Oct 30, 2026
…t__ (GH-160957) (#160961)

gh-137549: Handle BaseExceptionGroup in asyncio.Timeout.__aexit__ (GH-160957)

asyncio.timeout() inserted TimeoutError into the context chain of
sub-exceptions only for ExceptionGroup; do the same for
BaseExceptionGroup.
(cherry picked from commit a683f70)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants