Skip to content

Conversation

@dr-carlos
Copy link
Contributor

@dr-carlos dr-carlos commented Nov 19, 2025

  • BaseExceptionGroup.__repr__ now overrides BaseException.__repr__, using the group's exception tuple instead of the mutable argument passed in.
  • ComplexExtendsException (a private macro in Objects/exceptions.c) now has a parameter to modify the exception's __repr__ and not just its __str__.

📚 Documentation preview 📚: https://cpython-previews--141736.org.readthedocs.build/

@iritkatriel
Copy link
Member

Thanks.

We don't make user-visible changes to builtin types without a PEP, so this PR cannot be merged as is.

We could document current behaviour (i.e., don't mutate the list) if it's not clear from the docs and then consider if we want to change it.

If we do want to change it, maybe it should be to make a shallow copy of the list rather than make it a tuple (so the repr/str won't change and break existing code that relies on current behaviour).

@dr-carlos
Copy link
Contributor Author

Thanks.

We don't make user-visible changes to builtin types without a PEP, so this PR cannot be merged as is.

We could document current behaviour (i.e., don't mutate the list) if it's not clear from the docs and then consider if we want to change it.

If we do want to change it, maybe it should be to make a shallow copy of the list rather than make it a tuple (so the repr/str won't change and break existing code that relies on current behaviour).

Thanks for the quick response! That all makes sense.

Just to clarify - is c87b66b not a very similar change in this release without a PEP? But maybe I'm missing something :)

@iritkatriel
Copy link
Member

If you implement BaseExceptionGroup_repr so that the output doesn't change, then this change makes sense and can be merged and backported.

dr-carlos and others added 4 commits November 23, 2025 07:46
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Nov 26, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@picnixz
Copy link
Member

picnixz commented Nov 26, 2025

PyObject_Repr and PySequence_List can raise so we cannot continue calling the C API unless the calls succeeeded.

dr-carlos and others added 2 commits November 26, 2025 22:04
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@dr-carlos
Copy link
Contributor Author

Currently we're using PyList_Check and PyTuple_Check to determine whether we can use the list or tuple repr - is it worth doing exact checks here instead, in case list or tuple are subclassed whilst overriding the __repr__?

@dr-carlos
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Nov 26, 2025

Thanks for making the requested changes!

@picnixz, @iritkatriel: please review the changes made to this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants