Skip to content

contextlib.suppress converts instances of a subtype of ExceptionGroup to an instance of the ExceptionGroup class #119287

Closed
@DetachHead

Description

@DetachHead

Bug report

Bug description:

from contextlib import suppress

class FooException(Exception): ...

class FooExceptionGroup(ExceptionGroup[Exception]): ...

try:
    with suppress(FooException):
        raise FooExceptionGroup("", [Exception()])
except ExceptionGroup as e:
    print(type(e))

in this code, the suppress context manager is expected to have no effect, as a FooException is not being raised within it. instead, it gets converted to an ExceptionGroup then re-raised.

expected output:

<class '__main__.FooExceptionGroup'>

actual output:

<class 'ExceptionGroup'>

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12bugs and security fixes3.13bugs and security fixes3.14new features, bugs and security fixesdocsDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions