Skip to content

gh-139551: add support for BaseExceptionGroup in IDLE#139563

Merged
gpshead merged 15 commits intopython:mainfrom
Locked-chess-official:baseexceptiongroupsupport
Apr 12, 2026
Merged

gh-139551: add support for BaseExceptionGroup in IDLE#139563
gpshead merged 15 commits intopython:mainfrom
Locked-chess-official:baseexceptiongroupsupport

Conversation

@Locked-chess-official
Copy link
Copy Markdown
Contributor

@Locked-chess-official Locked-chess-official commented Oct 4, 2025

@Locked-chess-official
Copy link
Copy Markdown
Contributor Author

Locked-chess-official commented Oct 4, 2025

Now I have found one different between the IDLE and REPL in this change. However, I don't think it affects:
image

@Locked-chess-official
Copy link
Copy Markdown
Contributor Author

The change that if isinstance(val, BaseExceptionGroup) branch becomes a function alone is difficult because it is a closure function.

@picnixz picnixz changed the title gh-139551: add the support for BaseExceptionGroup gh-139551: support for BaseExceptionGroup in IDLE Oct 5, 2025
@picnixz picnixz changed the title gh-139551: support for BaseExceptionGroup in IDLE gh-139551: add support for BaseExceptionGroup in IDLE Oct 5, 2025
Copy link
Copy Markdown
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests and a What's New entry as well? I think the code could also avoid having all those if prefix: inside the for loops and many times, the additional string is either two spaces or the given prefix.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@picnixz
Copy link
Copy Markdown
Member

picnixz commented Oct 5, 2025

More generally, don't we have a helper in traceback for rendering exception groups actually? Can't we use it?

@Locked-chess-official
Copy link
Copy Markdown
Contributor Author

Locked-chess-official commented Oct 5, 2025

More generally, don't we have a helper in traceback for rendering exception groups actually? Can't we use it?

Maybe not. In IDLE, it need traceback.print_list to print the right tb. If we use it, one tb with file "<pyshell#x>" will have no code and there will be a tb exec(code). So the code must be writed alone here.

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Oct 5, 2025

Ok. For now, let's write it as is, and later we can rewrite the exception rendering logic by using the same approach as for traceback.TracebackException where we use a context for indentation. It could reduce the code complexity (compare the current code with traceback.TracebackException.format)

@Locked-chess-official
Copy link
Copy Markdown
Contributor Author

I have no idea whether to do it. What should be used is traceback._ExceptionPrintContext wich is a private attribute.

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Oct 5, 2025

No, I meant, we should mimic this ourselves. We may need to tweak the context itself, but the approach can be taken. Not in this PR though I would say as it may be too much changes in one PR.

@CoolCat467
Copy link
Copy Markdown
Contributor

I encounter exactly this issue all the time, sorry to bother again but @gpshead could you look at this as well whenever you have time?

gpshead and others added 5 commits April 11, 2026 23:58
The print call for the "exception has printed" message in
print_exc_group was writing to stdout instead of stderr.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The expression need_print_underline *= (i == len(exc.exceptions))
used bool*bool as a substitute for logical and. Replace with a
readable conditional.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Test nested groups, __cause__/__context__ chaining inside groups,
and cycle detection for the exception group display code.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…up rendering

Match the traceback module defaults (max_group_width=15,
max_group_depth=10) to prevent pathological exception groups from
producing unbounded output or stack overflow via recursion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gpshead gpshead self-assigned this Apr 12, 2026
Copy link
Copy Markdown
Member

@gpshead gpshead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I polished things a little & added tests, this should be ready, it appears to work as expected.

pie in the sky: I do wish idle didn't reinvent its own exception rendering and could just use the traceback module - but if it even makes sense to do that (it may not), it'd be an entirely different cleanup.

@gpshead gpshead merged commit 1e79bf6 into python:main Apr 12, 2026
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants