Repository navigation
Conversation
iritkatriel
approved these changes
Oct 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds tests for
except*handlers that raise aBaseExceptionthat isn't anException. Until now, every handler intest_except_star.pyraised anExceptionsubclass. This changes tests only; CPython already behaves correctly.Why
PyPy runs CPython's
test_except_star.pyand passes all of it, but gets this case wrong (pypy/pypy#5689). Itsexcept*re-raise logic asserts that every exception raised in a handler is anException, so raising e.g.KeyboardInterruptfrom a handler produces an internalAssertionError. Fixing that alone exposes a second bug: it builds anExceptionGroupwhere CPython builds aBaseExceptionGroup, which fails withTypeError: Cannot nest BaseExceptions in an ExceptionGroup. Neither bug was noticed because no test covered this case. It only came up through a test in theexceptiongroupbackport (agronholm/exceptiongroup#163), which now skips that test on PyPy.New tests in
TestExceptStarRaiseThey follow the existing
test_raise_*tests, but raise a localBaseExceptionsubclass. I used a local subclass rather thanKeyboardInterruptso that a broken implementation can't stop the test run by letting aKeyboardInterruptescape.test_raise_base_exception: part of the group is handled, so the result must be aBaseExceptionGroupholding the raised exception and the unhandled rest.test_raise_handle_all_raise_one_base_exception: the whole group is handled, so the raised exception propagates on its own.test_raise_handle_all_raise_base_exception_and_exception: two handlers raise aBaseExceptionand anException, so the result must be aBaseExceptionGroup.The two group tests check the group's type and members directly.
assertExceptionIsLikeonly looks insideExceptionGroupinstances; given aBaseExceptionGroup, it compares just the class and message.Testing
main(debug build):./python -m test test_except_starpasses (63 tests), and-R 3:3reports no leaks.test_except_star.py:py3.12from source with only theAssertionErrorfixed: the 2 tests expecting aBaseExceptionGroupfail.py3.12from source with both fixes from except*: AssertionError when a handler raises a non-Exception BaseException (e.g. KeyboardInterrupt) pypy/pypy#5689: all pass.No NEWS entry, since this only adds tests.