Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

contextlib.suppress does not support ExceptionGroups #103791

Closed
Labels
type-featureA feature request or enhancement
@ambv

Description

@ambv

Currently,contextlib.suppress does not successfully suppress exceptions that are wrapped within anExceptionGroup.

In other words, this works:

defraise_ve():raiseValueError("ve")withsuppress(ValueError):raise_ve()

while this doesn't:

defraise_ve_eg():raiseExceptionGroup("eg", [ValueError("ve")])withsuppress(ValueError):raise_ve_eg()

The user's intent is to suppress the latter case, too. It should work just as well, removingValueError instances from the exception group. If it ends up empty, nothing gets raised. Otherwise, anExceptionGroup should be re-raised with the remaining exceptions. For instance:

defraise_ve_eg3():raiseExceptionGroup("eg", [ValueError("ve1"),KeyError("ke"),ValueError("ve2")])withsuppress(ValueError):raise_ve_eg3()

should raise anExceptionGroup with theKeyError("ke") only, as we suppressed ValueError instances.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp