Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseExceptionGroup.derive doesn't preserve __cause__ etc. #99619

Closed
JelleZijlstra opened this issue Nov 20, 2022 · 1 comment · Fixed by #99621
Closed

BaseExceptionGroup.derive doesn't preserve __cause__ etc. #99619

JelleZijlstra opened this issue Nov 20, 2022 · 1 comment · Fixed by #99621
Labels
3.11 3.12 type-bug An unexpected behavior, bug, or error

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented Nov 20, 2022

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

@JelleZijlstra JelleZijlstra added type-bug An unexpected behavior, bug, or error 3.11 3.12 labels Nov 20, 2022
@iritkatriel
Copy link
Member

iritkatriel commented Nov 20, 2022

That's an error in the doc. I'll fix it. Thanks.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 23, 2022
…pythonGH-99621)

(cherry picked from commit 5d9183c)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
miss-islington added a commit that referenced this issue Nov 23, 2022
…9621)

(cherry picked from commit 5d9183c)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 3.12 type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants