Skip to content

asyncio.Timeout.__aexit__ does not handle BaseExceptionGroup #137549

Closed

Description

@PLPeeters

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:

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.

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

Activity

  1. gunyu1019 commented on Aug 15, 2025

    @gunyu1019

    @corona10, Let me try to fix this issue.

  2. self-assigned this
    on Aug 15, 2025
  3. corona10 commented on Aug 15, 2025

    @corona10
    Member

    Please go ahead!

  4. added a commit that references this issue on Aug 15, 2025
  5. added 3 commits that reference this issue on Oct 30, 2026
  6. asvetlov commented on Oct 30, 2026

    @asvetlov
    Contributor

    Fixed

  7. moved this from Todo to Done in asyncioon Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or error

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions