8000 BaseExceptionGroup.derive doesn't preserve __cause__ etc. · Issue #99619 · python/cpython · GitHub 10000
[go: up one dir, main page]

Skip to content
BaseExceptionGroup.derive doesn't preserve __cause__ etc. #99619
Closed
@JelleZijlstra

Description

@JelleZijlstra

The documentation for BaseExceptionGroup.derive says "Returns an exception group with the same message, __traceback__, __cause__, __context__ and __notes__ but which wraps the exceptions in excs."

But it doesn't, it only preserves the message:

Python 3.11.0 (v3.11.0:deaf509e8f, Oct 24 2022, 14:43:23) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> eg = BaseExceptionGroup("", [ValueError("included")])
>>> eg.add_note("note")
>>> eg.__cause__ = ValueError("cause")
>>> eg.__context__ = ValueError("context")
>>> derived = eg.derive([ValueError("derive")])
>>> derived.__notes__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'ExceptionGroup' object has no attribute '__notes__'. Did you mean: '__ne__'?
>>> derived.__cause__
derived.__cause__
>>> derived.__cause__
>>> derived.__context__
>>> derived.message
''

The code for BaseExceptionGroup.derive only uses self->msg from the original object:

BaseExceptionGroup_derive(PyObject *self_, PyObject *args)

cc @iritkatriel @Zac-HD for exceptiongroups and notes.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0