This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Better str() for BaseExceptionGroup
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, iritkatriel, yselivanov
Priority: normal Keywords: 3.2regression, patch

Created on 2022-02-12 11:02 by iritkatriel, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31294 merged iritkatriel, 2022-02-12 11:03
Messages (3)
msg413121 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-02-12 11:02
The str() of exception groups currently contains just the msg as passed to the constructor. This turned out to be confusing (see https://github.com/python/cpython/pull/31270#issuecomment-1036418346).

We should consider whether it is possible to design a more informative str().

Note that the str() is included in the standard traceback, which include the line:

f"{type(e)}: {str(e)}"

So str() should not repeat the type, and should not clutter this too much. Probably just the msg plus the number of contained leaf exceptions.

PEP 654 needs to be updated with what we do here, and the change needs to be approved by the SC.
msg413138 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2022-02-12 17:52
Should it show the number of immediate subexceptions (i.e., len(eg.exceptions)) or the number of leaf exceptions? I'd be happy with the former (since that's what EdgeDb's MultiError does), which would not require adding an extra field to the base exception group struct.
msg413735 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-02-22 18:29
New changeset 38b5acf8673ce42a401263a2528202e44d6ae60a by Irit Katriel in branch 'main':
bpo-46729: add number of sub-exceptions in str() of BaseExceptionGroup (GH-31294)
https://github.com/python/cpython/commit/38b5acf8673ce42a401263a2528202e44d6ae60a
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90885
2022-02-22 18:30:58iritkatrielsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-02-22 18:29:02iritkatrielsetmessages: + msg413735
2022-02-12 17:52:50gvanrossumsetnosy: + gvanrossum, yselivanov
messages: + msg413138
2022-02-12 11:03:13iritkatrielsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29453
2022-02-12 11:02:01iritkatrielcreate